Skip to content

tokubass/ex_exporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exporter

On the library side, you can specify functions and macros that the caller can use by default.

Examples

  defmodule MyModule do
    use Exporter, default: [a: 0, b: 1]

    def a, do: "a"
    def b(_), do: "b"
    def c, do: "c"

  end

  defmodule MyApp do
    use MyModule
    a()  # ok. default import
    b(1) # ok. default import
    c()  # error

    use MyModule, [c: 0]
    a()  # error
    b(1) # error
    c()  # ok
  end

  # allow override

  defmodule MyModule do

    use Exporter, default: [a: 0, b: 1]

    defmacro __using__(opt)  do
      ast = super(opt)
      quote do
        import Enum, only: [min: 1]
        unquote(ast)
      end
    end

  end

Installation

If available in Hex, the package can be installed by adding exporter to your list of dependencies in mix.exs:

def deps do
  [{:exporter, "~> 0.1.0"}]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/exporter.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages