Skip to content

Instantly share code, notes, and snippets.

@pikender
Last active April 13, 2016 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pikender/892fd3707043bacecc73ad24ba45cdba to your computer and use it in GitHub Desktop.
Save pikender/892fd3707043bacecc73ad24ba45cdba to your computer and use it in GitHub Desktop.
Model Support Function Extension
defmodule Nectar.ExtendProduct do
Module.register_attribute(__MODULE__, :method_block, accumulate: true)
include_method = fn(support_fn) -> Module.put_attribute(__MODULE__, :method_block, support_fn) end
include_method.(quote do: (def fn_from_outside, do: "support function"))
defmacro __before_compile__(_env) do
@method_block
end
end
defmodule Nectar.Product do
...
# Add new support function here
@before_compile Nectar.ExtendProduct
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment