Skip to content

Commit 5631505

Browse files
authored
Merge pull request #68 from Nezteb/master
Make `exports: :all` also export subdomains
2 parents 59af044 + c4d7441 commit 5631505

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

lib/boundary.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ defmodule Boundary do
182182
export all of these modules with the `exports: [{Schemas, except: [Base]}, ...]`. This will
183183
export all `MySystem.Schemas.*` modules, except for `MySystem.Schemas.Base`.
184184
185-
You can also export all modules of the boundary with `use Boundary, exports: :all`. To exclude
186-
some modules from the export list use, `use Boundary, exports: {:all, except: [SomeMod, ...]}`.
185+
You can also export all modules of the boundary with `use Boundary, exports: :all`. This will also
186+
export all sub-modules of the boundary. To exclude some modules from the export list use,
187+
`use Boundary, exports: {:all, except: [SomeMod, ...]}`.
187188
188189
Mass export is not advised in most situations. Prefer explicitly listing exported modules. If
189190
your export list is long, it's a possible indication of an overly fragmented interface. Consider

lib/boundary/checker.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,15 @@ defmodule Boundary.Checker do
127127
|> Stream.take_while(&(not is_nil(&1)))
128128
|> Enum.find(&(Enum.at(&1.ancestors, 0) == boundary.name))
129129
|> case do
130-
nil -> false
131-
child_subboundary -> export in [child_subboundary.name | child_subboundary.exports]
130+
nil ->
131+
false
132+
133+
# If the export's `owner_boundary` exports all modules, include sub-modules
134+
%{exports: [{export_module, []}]} ->
135+
String.starts_with?(to_string(export), to_string(export_module))
136+
137+
child_subboundary ->
138+
export in [child_subboundary.name | child_subboundary.exports]
132139
end
133140
end
134141
end

test/mix/tasks/compile/boundary_test.exs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,13 +1147,27 @@ defmodule Mix.Tasks.Compile.BoundaryTest do
11471147
module1 = unique_module_name()
11481148
module2 = unique_module_name()
11491149

1150-
module_test "exporting all modules",
1150+
module_test "exporting all modules and exports of all nested boundaries",
11511151
"""
11521152
defmodule #{module1} do
11531153
use Boundary, exports: :all
11541154
11551155
defmodule Schemas.Foo do def fun(), do: :ok end
11561156
defmodule Schemas.Bar do def fun(), do: :ok end
1157+
1158+
defmodule SubModule do
1159+
use Boundary, exports: [Module]
1160+
1161+
def fun(), do: :ok
1162+
1163+
defmodule Module do
1164+
def fun(), do: :ok
1165+
1166+
defmodule Private do
1167+
def fun(), do: :ok
1168+
end
1169+
end
1170+
end
11571171
end
11581172
11591173
defmodule #{module2} do
@@ -1163,10 +1177,16 @@ defmodule Mix.Tasks.Compile.BoundaryTest do
11631177
#{module1}.Schemas.Foo.fun()
11641178
#{module1}.Schemas.Bar.fun()
11651179
#{module1}.Schemas.Base.fun()
1180+
#{module1}.SubModule.fun()
1181+
#{module1}.SubModule.Module.fun()
1182+
#{module1}.SubModule.Module.Private.fun()
11661183
end
11671184
end
11681185
""" do
1169-
assert warnings == []
1186+
assert [warning] = warnings
1187+
1188+
assert warning.message =~
1189+
"forbidden reference to #{unquote(module1)}.SubModule.Module.Private"
11701190
end
11711191

11721192
module1 = unique_module_name()

0 commit comments

Comments
 (0)