diff --git a/docs/then.md b/docs/then.md index 98c254c..b037f8c 100644 --- a/docs/then.md +++ b/docs/then.md @@ -44,7 +44,7 @@ You can also call functions from other modules: defmodule Calculator do use Then - @then {Logger, :info} + @then {IO, :puts} def multiply(a, b) do a * b end @@ -62,6 +62,20 @@ defmodule MyAudit do end ``` +**Aliased modules work too:** + +```elixir +defmodule Calculator do + alias IO, as: MyIO + use Then + + @then {MyIO, :puts} + def calculate(x) do + x * 2 + end +end +``` + ### Real-world Example ```elixir @@ -77,8 +91,8 @@ defmodule UserService do end # side effects separately - def audit_creation({:ok, user}), do: Logger.info("User #{user.email} created") - def audit_creation({:error, reason}), do: Logger.warn("User wasn't created. #{reason}") + def audit_creation({:ok, user}), do: IO.puts("✅ User #{user.email} created") + def audit_creation({:error, reason}), do: IO.puts("❌ User creation failed: #{reason}") end ``` diff --git a/mix.exs b/mix.exs index a71d495..b09c3c3 100644 --- a/mix.exs +++ b/mix.exs @@ -36,12 +36,12 @@ defmodule Then.MixProject do defp docs do [ - main: "then", + main: "getting-started", source_url: "https://github.com/bardoor/then", extras: [ - "docs/then.md", - "CHANGELOG.md", - "LICENSE" + {"docs/then.md", title: "Getting Started", filename: "getting-started"}, + {"CHANGELOG.md", title: "Changelog"}, + {"LICENSE", title: "License"} ], groups_for_extras: [ "Documentation": ["docs/then.md"], diff --git a/test/then_test.exs b/test/then_test.exs index 7ab3d04..d4bd16b 100644 --- a/test/then_test.exs +++ b/test/then_test.exs @@ -1,5 +1,7 @@ defmodule ThenTest do use ExUnit.Case + import ExUnit.CaptureIO + doctest Then defmodule TestModule do @@ -579,4 +581,25 @@ defmodule ThenTest do assert_received {:arity_1, "one arg: z"} end end + + describe "aliased external modules" do + test "works with aliased modules" do + defmodule AliasedTest do + alias IO, as: MyIO + use Then + + @then {MyIO, :puts} + def test_aliased_call(value) do + value * 2 + end + end + + output = capture_io(fn -> + result = AliasedTest.test_aliased_call(5) + assert result == 10 + end) + + assert output == "10\n" + end + end end