From 5462d08463ac6f4cb826eaa56aaabca2e495ab95 Mon Sep 17 00:00:00 2001 From: bardoor Date: Wed, 27 Aug 2025 02:19:10 +0300 Subject: [PATCH 1/3] fix(docs): correct main page configuration for ExDoc --- mix.exs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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"], From 992848bfcf8544c84df47555f072990eedda5dc3 Mon Sep 17 00:00:00 2001 From: bardoor Date: Wed, 27 Aug 2025 02:26:23 +0300 Subject: [PATCH 2/3] test(then): add aliases test --- test/then_test.exs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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 From 5bb815cde7413e6f9d4a96ac13c8e097012707f3 Mon Sep 17 00:00:00 2001 From: bardoor Date: Wed, 27 Aug 2025 02:26:51 +0300 Subject: [PATCH 3/3] docs: add aliases modules support description --- docs/then.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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 ```