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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d68f714812e20170c2ee5c5317e29b64c8ebbae25431492f457ae4b53263d50e
4
- data.tar.gz: bae431b97f2e98ff2a28ed9712ab415a3e3b2dfe18753e46d93be5acfa86a9f6
3
+ metadata.gz: 595e557959d0639e93e97244f510db28bd024e524fbca3bbdf0223546e7ee52d
4
+ data.tar.gz: d01f6e5c5d3d06c9fb3cb8bf3d7ed92f2b321952d99b3f04d19af77f14ffe388
5
5
  SHA512:
6
- metadata.gz: 1035694fa2c676b368938c61ecc21d1403fe8b68f151dba1ef80e9fc7b9166460f09a0e9c6aa275dcd005b615fd66c08dce5ae5f6b6b4f02421241ff266f8ca1
7
- data.tar.gz: cb84d351c30f19dd86c7351351ec29ffd01e930f21ba2aece3061724ed1c7cc2a0ca3d43ec8ea0335a0741ada0debf683d379f8fa48eb12c521a2ba057fa66d8
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
@@ -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| owner_of(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 owner_of(class_name) = @interfaces.key(class_name) || @owners.find { |_hub, classes| classes.include?(class_name) }&.first
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/")
@@ -1,3 +1,3 @@
1
1
  module HubKernel
2
- VERSION = "0.13.0"
2
+ VERSION = "0.14.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hub_kernel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider