From db8693e0222418d1a1becf2dbe060d49b59f53ff Mon Sep 17 00:00:00 2001 From: Noah Betzen Date: Wed, 25 Sep 2024 15:23:34 -0700 Subject: [PATCH] Cleanup; add docs --- lib/boundary.ex | 5 +++-- lib/boundary/checker.ex | 5 +++-- test/mix/tasks/compile/boundary_test.exs | 13 +++++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/boundary.ex b/lib/boundary.ex index ad1d723..958c20d 100644 --- a/lib/boundary.ex +++ b/lib/boundary.ex @@ -182,8 +182,9 @@ defmodule Boundary do export all of these modules with the `exports: [{Schemas, except: [Base]}, ...]`. This will export all `MySystem.Schemas.*` modules, except for `MySystem.Schemas.Base`. - You can also export all modules of the boundary with `use Boundary, exports: :all`. To exclude - some modules from the export list use, `use Boundary, exports: {:all, except: [SomeMod, ...]}`. + You can also export all modules of the boundary with `use Boundary, exports: :all`. This will also + export all sub-modules of the boundary. To exclude some modules from the export list use, + `use Boundary, exports: {:all, except: [SomeMod, ...]}`. Mass export is not advised in most situations. Prefer explicitly listing exported modules. If your export list is long, it's a possible indication of an overly fragmented interface. Consider diff --git a/lib/boundary/checker.ex b/lib/boundary/checker.ex index f1c8e5e..64e8f60 100644 --- a/lib/boundary/checker.ex +++ b/lib/boundary/checker.ex @@ -130,8 +130,9 @@ defmodule Boundary.Checker do nil -> false - %{exports: [{_, []}]} = child_subboundary -> - String.starts_with?(to_string(export), to_string(child_subboundary.name)) + # If the export's `owner_boundary` exports all modules, include sub-modules + %{exports: [{export_module, []}]} -> + String.starts_with?(to_string(export), to_string(export_module)) child_subboundary -> export in [child_subboundary.name | child_subboundary.exports] diff --git a/test/mix/tasks/compile/boundary_test.exs b/test/mix/tasks/compile/boundary_test.exs index 8329b44..3f83899 100644 --- a/test/mix/tasks/compile/boundary_test.exs +++ b/test/mix/tasks/compile/boundary_test.exs @@ -1147,7 +1147,7 @@ defmodule Mix.Tasks.Compile.BoundaryTest do module1 = unique_module_name() module2 = unique_module_name() - module_test "exporting all modules and submodules", + module_test "exporting all modules and sub-modules", """ defmodule #{module1} do use Boundary, exports: :all @@ -1155,13 +1155,17 @@ defmodule Mix.Tasks.Compile.BoundaryTest do defmodule Schemas.Foo do def fun(), do: :ok end defmodule Schemas.Bar do def fun(), do: :ok end - defmodule Subdomain do + defmodule SubModule do use Boundary, exports: :all def fun(), do: :ok defmodule Module do def fun(), do: :ok + + defmodule Another do + def fun(), do: :ok + end end end end @@ -1173,8 +1177,9 @@ defmodule Mix.Tasks.Compile.BoundaryTest do #{module1}.Schemas.Foo.fun() #{module1}.Schemas.Bar.fun() #{module1}.Schemas.Base.fun() - #{module1}.Subdomain.fun() - #{module1}.Subdomain.Module.fun() + #{module1}.SubModule.fun() + #{module1}.SubModule.Module.fun() + #{module1}.SubModule.Module.Another.fun() end end """ do