Current section
7 Versions
Jump to
Current section
7 Versions
Compare versions
6
files changed
+29
additions
-7
deletions
| @@ -18,7 +18,7 @@ by adding `delx` to your list of dependencies in `mix.exs`: | |
| 18 18 | ```elixir |
| 19 19 | def deps do |
| 20 20 | [ |
| 21 | - {:delx, "~> 2.0.0"} |
| 21 | + {:delx, "~> 2.0.1"} |
| 22 22 | ] |
| 23 23 | end |
| 24 24 | ``` |
| @@ -15,4 +15,4 @@ | |
| 15 15 | [{<<"Source">>,<<"https://github.com/i22-digitalagentur/delx">>}]}. |
| 16 16 | {<<"name">>,<<"delx">>}. |
| 17 17 | {<<"requirements">>,[]}. |
| 18 | - {<<"version">>,<<"2.0.0">>}. |
| 18 | + {<<"version">>,<<"2.0.1">>}. |
| @@ -13,7 +13,7 @@ defmodule Delx do | |
| 13 13 | ...> end |
| 14 14 | |
| 15 15 | You can delegate functions calls to another module by using the `Delx` |
| 16 | - module and calling the `defdel/2` macro in the module body. It has |
| 16 | + module and calling the `Delx.Defdel.defdel/2` macro in the module body. It has |
| 17 17 | the same API as Elixir's own `Kernel.defdelegate/2` macro. |
| 18 18 | |
| 19 19 | iex> defmodule Greeter do |
| @@ -25,6 +25,11 @@ defmodule Delx do | |
| 25 25 | iex> Greeter.hello("Tobi") |
| 26 26 | "Hello, Tobi!" |
| 27 27 | |
| 28 | + The reason you need to use `Delx` and define the `:otp_app` option is that |
| 29 | + each application can configure their own delegation behavior. So third-party |
| 30 | + libaries that also use Delx remain unaffected of your application-specific |
| 31 | + configuration. |
| 32 | + |
| 28 33 | ## Testing |
| 29 34 | |
| 30 35 | One great benefit of Delx is that you can test delegation without invoking |
| @@ -1,6 +1,23 @@ | |
| 1 1 | defmodule Delx.Defdel do |
| 2 | - @moduledoc false |
| 2 | + @moduledoc """ |
| 3 | + A module defining a macro to define delegate functions. |
| 4 | + """ |
| 3 5 | |
| 6 | + @doc """ |
| 7 | + You can delegate functions calls to another module by using the `Delx` |
| 8 | + module and calling the `defdel/2` macro in the module body. It has |
| 9 | + the same API as Elixir's own `Kernel.defdelegate/2` macro. |
| 10 | + |
| 11 | + ## Example |
| 12 | + |
| 13 | + Before calling `defdel/2`, you need to use `Delx`. |
| 14 | + |
| 15 | + iex> defmodule Greeter do |
| 16 | + ...> use Delx, otp_app: :greeter |
| 17 | + |
| 18 | + ...> defdel hello(name), to: Greeter.StringGreeter, as: :welcome |
| 19 | + ...> end |
| 20 | + """ |
| 4 21 | defmacro defdel(funs, opts) do |
| 5 22 | funs = Macro.escape(funs, unquote: true) |
| @@ -3,9 +3,9 @@ defmodule Delx.TestAssertions do | |
| 3 3 | A module that contains assertions for `ExUnit` to test function delegation. |
| 4 4 | |
| 5 5 | Note that you need to activate stubbing for your test environment in order to |
| 6 | - make the assertions work. In your `config/text.exs` file: |
| 6 | + make the assertions work. In your `config/test.exs` file: |
| 7 7 | |
| 8 | - config :delx, :stub, true |
| 8 | + config :my_app, Delx, stub: true |
| 9 9 | """ |
| 10 10 | |
| 11 11 | import Exception, only: [format_mfa: 3] |
Loading more files…