hub_kernel 0.12.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 +8 -1
- data/lib/hub_kernel/conformance/crossings.rb +5 -0
- data/lib/hub_kernel/crossings.rb +16 -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
|
|
@@ -199,6 +203,9 @@ end
|
|
|
199
203
|
- It also fails naming each class defined in the files it reads that no hub owns, such as
|
|
200
204
|
"No hub owns Shop::Refund", and each class the map gives to two hubs, such as "Two hubs
|
|
201
205
|
own Shop::Receipt".
|
|
206
|
+
- It fails naming each class the map names that no longer exists in the app, such as "The
|
|
207
|
+
map names Shop::Ghost, which does not exist", so a renamed or removed class does not
|
|
208
|
+
stay in the map.
|
|
202
209
|
|
|
203
210
|
## Installation
|
|
204
211
|
Add this line to your application's Gemfile:
|
|
@@ -34,6 +34,11 @@ module HubKernel
|
|
|
34
34
|
twice = the_crossings.claimed_twice
|
|
35
35
|
assert twice.empty?, twice.map { |name| "Two hubs own #{name}" }.join("\n")
|
|
36
36
|
end
|
|
37
|
+
|
|
38
|
+
test "every class the map names exists" do
|
|
39
|
+
missing = the_crossings.missing_classes
|
|
40
|
+
assert missing.empty?, missing.map { |name| "The map names #{name}, which does not exist" }.join("\n")
|
|
41
|
+
end
|
|
37
42
|
end
|
|
38
43
|
|
|
39
44
|
def crossing_paths = (Dir.glob(crossing_files, base: crossing_root) - crossing_exceptions).sort
|
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)
|
|
@@ -22,6 +23,8 @@ module HubKernel
|
|
|
22
23
|
|
|
23
24
|
def claimed_twice = @owners.values.flatten.tally.select { |_name, hubs| hubs > 1 }.keys
|
|
24
25
|
|
|
26
|
+
def missing_classes = @owners.values.flatten.uniq.reject(&:safe_constantize)
|
|
27
|
+
|
|
25
28
|
private
|
|
26
29
|
|
|
27
30
|
def class_of(path) = path.sub(%r{\Aapp/[^/]+/}, "").delete_suffix(".rb").camelize
|
|
@@ -34,10 +37,20 @@ module HubKernel
|
|
|
34
37
|
|
|
35
38
|
def owned_class_in(name)
|
|
36
39
|
parts = name.split("::")
|
|
37
|
-
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)
|
|
42
|
+
end
|
|
43
|
+
|
|
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}"
|
|
38
47
|
end
|
|
39
48
|
|
|
40
|
-
def
|
|
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
|
|
41
54
|
|
|
42
55
|
def owner_of_file(path)
|
|
43
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