ex_shards v0.2.1 ExShards.Construct

This is an utility module, which provides a set of macros to inject functions from Erlang modules.

Link to this section Summary

Functions

Injects exported functions from an Erlang module

Link to this section Functions

Link to this macro inject(mod, opts \\ []) (macro)

Injects exported functions from an Erlang module.

By default, it injects all functions from the given module:

inject :lists

Alternatively, it allows you to pass pairs of name/arities to :except as a fine grained control on what to inject (or not):

inject :lists, except: [append: 1]

Besides, it allows you to pass only the name of the fuction(s) to :except, in order to exclude all function that matches with that name – no matter the arity. E.g.:

inject :lists, except: [:append]

This will exclude either :lists.append/1 and :lists.append/2.

Example

defmodule Utils do
  use ExShards.Construct

  # injects all exported functions in module `:lists`
  inject :lists

  # injects all exported functions in module `:maps` except:
  # [`:maps.get/2`](http://www.erlang.org/doc/man/maps.html#get-2), [`:maps.get/3`](http://www.erlang.org/doc/man/maps.html#get-3) and [`:maps.find/2`](http://www.erlang.org/doc/man/maps.html#find-2).
  inject :maps, except: [:get, find: 2]
end