Function Decorating v0.0.5 FunctionDecorating

Add a function decorating availability to a module.

Usage

Decorating in dev with log decorator.

defmodule User do
  use FunctionDecorating
  decorate_fn_with(LogDecorator)

  def say(word) do
    word
  end
end

iex >User.say("hello")
#PID<0.86.0> [x] Elixir.User.say(["hello"]) -> "hello"
"hello"

Default usage is for Mix.env == :dev only. To override it:

defmodule User do
  use FunctionDecorating mix_envs: [:prod]
  decorate_fn_with(LogDecorator)

  def say(word) do
    word
  end
end

iex >Mix.env
:prod

iex >User.say("hello")
#PID<0.86.0> [x] Elixir.User.say(["hello"]) -> "hello"
"hello"

Summary

Macros

The decorator mechanism. Override the original Kernel.def by not inlucing it in the import statement

Functions

calc_args(args_ast, current_env \\ Mix.env())
decorate_function_def(fn_def, list)
do_def(fn_call_ast, fn_options_ast)
do_using(args_ast)
generate_bare_using_ast()
generate_using_ast()

Macros

decorate_fn_with(decorator_ast, options_ast \\ Macro.escape([]))
def(fn_call_ast, fn_options_ast)

The decorator mechanism. Override the original Kernel.def by not inlucing it in the import statement.