hub_kernel 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/hub_kernel/crossings.rb +14 -3
- data/lib/hub_kernel/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 595e557959d0639e93e97244f510db28bd024e524fbca3bbdf0223546e7ee52d
|
|
4
|
+
data.tar.gz: d01f6e5c5d3d06c9fb3cb8bf3d7ed92f2b321952d99b3f04d19af77f14ffe388
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 988f17639404b44e3e25772160c14a504541abd2981f21587357ddd8175419784553143cb42e63b66adbbc07102a0a8488f735711cfd724fd26e3e180a370295
|
|
7
|
+
data.tar.gz: cfa7009ca3d343f8da7c0429802c7b32df0a3d4a39af4260f43ef25e8f28d35b07254b27094233bbb860cef39832b4bad52e1669941a4dccbc16dd432e3c833b
|
data/README.md
CHANGED
|
@@ -180,7 +180,8 @@ class HubCrossingsTest < ActiveSupport::TestCase
|
|
|
180
180
|
owners: { supplies: %w[Shop::Purchase Shop::PurchasesController], finance: %w[Shop::Expense], shop: %w[Shop::Home] },
|
|
181
181
|
shared: %w[Shop::BaseController],
|
|
182
182
|
host_layer: :shop,
|
|
183
|
-
interfaces: { supplies: "Shop::Hubs::Supplies", finance: "Shop::Hubs::Finance" }
|
|
183
|
+
interfaces: { supplies: "Shop::Hubs::Supplies", finance: "Shop::Hubs::Finance" },
|
|
184
|
+
namespaces: { billing: %w[Billing] }
|
|
184
185
|
)
|
|
185
186
|
end
|
|
186
187
|
end
|
|
@@ -189,6 +190,9 @@ end
|
|
|
189
190
|
- A constant inside another hub's class counts as naming that class.
|
|
190
191
|
- A name no hub owns, such as a namespace, is not a crossing, and neither is a class on
|
|
191
192
|
the `shared` list.
|
|
193
|
+
- `namespaces` gives a hub every class under a namespace, such as a hub gem's `Billing`,
|
|
194
|
+
so its classes need not be listed one by one. A class listed by name in `owners`
|
|
195
|
+
belongs to its listed hub even under another hub's namespace.
|
|
192
196
|
- A view belongs to the hub that owns its controller, then to the hub that owns the
|
|
193
197
|
record its folder is named after, and otherwise to the `host_layer`.
|
|
194
198
|
- The host's layer may name any hub's interface module, and a hub naming another hub's
|
data/lib/hub_kernel/crossings.rb
CHANGED
|
@@ -2,11 +2,12 @@ require "active_support/core_ext/string/inflections"
|
|
|
2
2
|
|
|
3
3
|
module HubKernel
|
|
4
4
|
class Crossings
|
|
5
|
-
def initialize(owners:, shared: [], host_layer: nil, interfaces: {})
|
|
5
|
+
def initialize(owners:, shared: [], host_layer: nil, interfaces: {}, namespaces: {})
|
|
6
6
|
@owners = owners
|
|
7
7
|
@shared = shared
|
|
8
8
|
@host_layer = host_layer
|
|
9
9
|
@interfaces = interfaces
|
|
10
|
+
@namespaces = namespaces
|
|
10
11
|
end
|
|
11
12
|
|
|
12
13
|
def in(path, source)
|
|
@@ -36,10 +37,20 @@ module HubKernel
|
|
|
36
37
|
|
|
37
38
|
def owned_class_in(name)
|
|
38
39
|
parts = name.split("::")
|
|
39
|
-
parts.size.downto(1).map { |size| parts.first(size).join("::") }.find { |candidate|
|
|
40
|
+
listed = parts.size.downto(1).map { |size| parts.first(size).join("::") }.find { |candidate| listed_owner_of(candidate) }
|
|
41
|
+
listed || class_under_namespace(name)
|
|
40
42
|
end
|
|
41
43
|
|
|
42
|
-
def
|
|
44
|
+
def class_under_namespace(name)
|
|
45
|
+
space = @namespaces.values.flatten.find { |namespace| name.start_with?("#{namespace}::") }
|
|
46
|
+
space && "#{space}::#{name.delete_prefix("#{space}::").split("::").first}"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def listed_owner_of(class_name) = @interfaces.key(class_name) || @owners.find { |_hub, classes| classes.include?(class_name) }&.first
|
|
50
|
+
|
|
51
|
+
def owner_of(class_name) = listed_owner_of(class_name) || owner_of_namespace(class_name)
|
|
52
|
+
|
|
53
|
+
def owner_of_namespace(class_name) = @namespaces.find { |_hub, spaces| spaces.any? { |space| class_name.start_with?("#{space}::") } }&.first
|
|
43
54
|
|
|
44
55
|
def owner_of_file(path)
|
|
45
56
|
return owner_of_view_folder(File.dirname(path.delete_prefix("app/views/")).camelize) if path.start_with?("app/views/")
|
data/lib/hub_kernel/version.rb
CHANGED