Skip to content

Commit

Permalink
Merge pull request #68 from Nezteb/master
Browse files Browse the repository at this point in the history
Make `exports: :all` also export subdomains
  • Loading branch information
sasa1977 authored Oct 4, 2024
2 parents 59af044 + c4d7441 commit 5631505
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/boundary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions lib/boundary/checker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,15 @@ defmodule Boundary.Checker do
|> Stream.take_while(&(not is_nil(&1)))
|> Enum.find(&(Enum.at(&1.ancestors, 0) == boundary.name))
|> case do
nil -> false
child_subboundary -> export in [child_subboundary.name | child_subboundary.exports]
nil ->
false

# 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]
end
end
end
Expand Down
24 changes: 22 additions & 2 deletions test/mix/tasks/compile/boundary_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,13 +1147,27 @@ defmodule Mix.Tasks.Compile.BoundaryTest do
module1 = unique_module_name()
module2 = unique_module_name()

module_test "exporting all modules",
module_test "exporting all modules and exports of all nested boundaries",
"""
defmodule #{module1} do
use Boundary, exports: :all
defmodule Schemas.Foo do def fun(), do: :ok end
defmodule Schemas.Bar do def fun(), do: :ok end
defmodule SubModule do
use Boundary, exports: [Module]
def fun(), do: :ok
defmodule Module do
def fun(), do: :ok
defmodule Private do
def fun(), do: :ok
end
end
end
end
defmodule #{module2} do
Expand All @@ -1163,10 +1177,16 @@ defmodule Mix.Tasks.Compile.BoundaryTest do
#{module1}.Schemas.Foo.fun()
#{module1}.Schemas.Bar.fun()
#{module1}.Schemas.Base.fun()
#{module1}.SubModule.fun()
#{module1}.SubModule.Module.fun()
#{module1}.SubModule.Module.Private.fun()
end
end
""" do
assert warnings == []
assert [warning] = warnings

assert warning.message =~
"forbidden reference to #{unquote(module1)}.SubModule.Module.Private"
end

module1 = unique_module_name()
Expand Down

0 comments on commit 5631505

Please sign in to comment.