Ecbolic v0.2.4 Ecbolic View Source

This module aims to provide a simple interface to Ecbolic.Store and the neccessary tools to add documentation to functions, which is easly accessable at runtime. This library was build with the intend to make it easy to show help for users of applications, such as chat bots.

In order to start creating documentation you first need to use this module

defmodule TestModule do
  use Ecbolic

Then you can start adding your documentation like using the macro Ecbolic.help/1. Modules without macro call above them will be ignored

Ecbolic.help("returns `:world`")
def hello, do: :world

In order to access the entries, you first have to load them. The function load_help() will be added when you use Ecbolic in your module. Calling this function will load the documentation you created into Ecbolic.Store, where it can be accessed from anywhere.

TestModule.load_help()

Under the hood this macro (ab)uses a feature added to Elixir 1.7, which allows you to add meta data to your documentation. So the snippet above will turn out like this:

@doc help: "returns `:world`"
def hello, do: :world

Both forms are valid to use, but you should stick with macro, so that it’ll continue to work, when the an other key will be used.

By default functions are stored with their function names. So the function hello will be turned into :hello. In case you want your function to be named by a different name, you can do so, by aliasing it with Ecbolix.alias/1. The internal function name will then be replaced with whatever you provide here. Even though, I suggest to restrain yourself to only use names, which can be turned into a string, such as string as atom. Things that cannot be turned into Strings will cause Ecbolic.Pretty problems when formatting the entries.

Ecbolic.help("returns `:world`")
Ecbolic.alias("Hello world") # Allows for spaces
def hello, do: :world

You can also group all functions within a module with the macro Ecbolic.group/1.

Ecbolic.group("memes")
def hello_there, do: "General Kenobi"

Ungrouped functions, will be grouped with :default by default.

Link to this section Summary

Functions

Aliases the name by with the documentation for a functions is accessed

Returns all help entries as a map, where each function is mapped it’s documentation

Returns the documentation for the one requested function. Will return nil, if it was not found

Sets the group for all functions in that module

Creates a documentation for the function below

Returns all functions in the given group, mapped to their documentation

Link to this section Types

Link to this type atom_or_string() View Source
atom_or_string() :: atom() | String.t()

Link to this section Functions

Aliases the name by with the documentation for a functions is accessed

Link to this function fetch_help() View Source
fetch_help() :: %{optional(atom_or_string()) => String.t()}

Returns all help entries as a map, where each function is mapped it’s documentation

Link to this function fetch_help(names) View Source
fetch_help([atom_or_string()]) :: %{optional(atom_or_string()) => String.t()}
fetch_help(atom_or_string()) :: String.t()

Returns the documentation for the one requested function. Will return nil, if it was not found

Sets the group for all functions in that module

Creates a documentation for the function below

Link to this function help_group(group_name) View Source
help_group(atom_or_string()) :: %{optional(atom_or_string()) => String.t()}

Returns all functions in the given group, mapped to their documentation