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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 229fcc87e3137795f02b73e3f0be126e9809181b14446e09e8a1a050fa83420e
4
- data.tar.gz: 2347fa14b7911dda34f7e1cbebb924eb10f99f8da0e5e086f112f78aa79440b9
3
+ metadata.gz: 595e557959d0639e93e97244f510db28bd024e524fbca3bbdf0223546e7ee52d
4
+ data.tar.gz: d01f6e5c5d3d06c9fb3cb8bf3d7ed92f2b321952d99b3f04d19af77f14ffe388
5
5
  SHA512:
6
- metadata.gz: e432500a7d6b4dc4c0e7a4061d74dfc81108435a640d4098afaa0a9ca58518790b75d94ba5e5d49e28c87e88925a1b6369f36968cc5b9fafb31480034730ecde
7
- data.tar.gz: fbf852ad51486ad330f5b7b0cefa7f36d599c7c713a0a95e2cffcbd689e41ea0042550a00e24c66a19778507e32ff992001aa90828ea10f6c8ed2d4f6d74f644
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
@@ -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| 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)
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 owner_of(class_name) = @interfaces.key(class_name) || @owners.find { |_hub, classes| classes.include?(class_name) }&.first
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/")
@@ -1,3 +1,3 @@
1
1
  module HubKernel
2
- VERSION = "0.12.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.12.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider