hub_kernel 0.11.0 → 0.13.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: 582093847b3b8cf75dbadd831d8a68df615bebccce57eeb89be12d3496fc89f0
4
- data.tar.gz: 4544cb83a72d80f920abbf78f6eee6984b4ab8d28e330d568eb86bd21ef97dc8
3
+ metadata.gz: d68f714812e20170c2ee5c5317e29b64c8ebbae25431492f457ae4b53263d50e
4
+ data.tar.gz: bae431b97f2e98ff2a28ed9712ab415a3e3b2dfe18753e46d93be5acfa86a9f6
5
5
  SHA512:
6
- metadata.gz: e5d72c62b32c671f49ae4babcc4755dd871fc4fcfaa35573c78689250ca6b27774bb9ce2db460405940774fc017d1abd742da4df1d646565f8df770d379deb00
7
- data.tar.gz: 4d5dff84ef2be0d5ebc3a53ce43e22e42d5d73ad53b0601663139f3fc0a68876e8c874a1833c200d078b29684d0bcd4056f11dd84150c0181dc6462943e9262a
6
+ metadata.gz: 1035694fa2c676b368938c61ecc21d1403fe8b68f151dba1ef80e9fc7b9166460f09a0e9c6aa275dcd005b615fd66c08dce5ae5f6b6b4f02421241ff266f8ca1
7
+ data.tar.gz: cb84d351c30f19dd86c7351351ec29ffd01e930f21ba2aece3061724ed1c7cc2a0ca3d43ec8ea0335a0741ada0debf683d379f8fa48eb12c521a2ba057fa66d8
data/README.md CHANGED
@@ -196,6 +196,12 @@ end
196
196
  - The test fails with "The crossing check found no files to read" when none of the files
197
197
  it read belongs to a hub or the host's layer, so a wrong `files:` pattern or an empty
198
198
  map does not pass unnoticed.
199
+ - It also fails naming each class defined in the files it reads that no hub owns, such as
200
+ "No hub owns Shop::Refund", and each class the map gives to two hubs, such as "Two hubs
201
+ own Shop::Receipt".
202
+ - It fails naming each class the map names that no longer exists in the app, such as "The
203
+ map names Shop::Ghost, which does not exist", so a renamed or removed class does not
204
+ stay in the map.
199
205
 
200
206
  ## Installation
201
207
  Add this line to your application's Gemfile:
@@ -17,15 +17,31 @@ module HubKernel
17
17
 
18
18
  included do
19
19
  test "no file names a class another hub owns" do
20
- paths = (Dir.glob(crossing_files, base: crossing_root) - crossing_exceptions).sort
21
- flunk "The crossing check found no files to read" if paths.none? { |path| the_crossings.belongs?(path) }
20
+ flunk "The crossing check found no files to read" if crossing_paths.none? { |path| the_crossings.belongs?(path) }
22
21
 
23
- found = paths.flat_map do |path|
22
+ found = crossing_paths.flat_map do |path|
24
23
  the_crossings.in(path, File.read(File.join(crossing_root, path))).map { |name| "#{path} names #{name}" }
25
24
  end
26
25
  assert found.empty?, found.join("\n")
27
26
  end
27
+
28
+ test "every class it reads belongs to a hub" do
29
+ unowned = the_crossings.unowned_classes(crossing_paths)
30
+ assert unowned.empty?, unowned.map { |name| "No hub owns #{name}" }.join("\n")
31
+ end
32
+
33
+ test "no class belongs to two hubs" do
34
+ twice = the_crossings.claimed_twice
35
+ assert twice.empty?, twice.map { |name| "Two hubs own #{name}" }.join("\n")
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
28
42
  end
43
+
44
+ def crossing_paths = (Dir.glob(crossing_files, base: crossing_root) - crossing_exceptions).sort
29
45
  end
30
46
  end
31
47
  end
@@ -16,8 +16,18 @@ module HubKernel
16
16
 
17
17
  def belongs?(path) = !owner_of_file(path).nil?
18
18
 
19
+ def unowned_classes(paths)
20
+ paths.select { |path| path.end_with?(".rb") && !path.start_with?("app/views/") }.map { |path| class_of(path) }.reject { |name| owner_of(name) }
21
+ end
22
+
23
+ def claimed_twice = @owners.values.flatten.tally.select { |_name, hubs| hubs > 1 }.keys
24
+
25
+ def missing_classes = @owners.values.flatten.uniq.reject(&:safe_constantize)
26
+
19
27
  private
20
28
 
29
+ def class_of(path) = path.sub(%r{\Aapp/[^/]+/}, "").delete_suffix(".rb").camelize
30
+
21
31
  def crossing?(name, hub)
22
32
  return false if @shared.include?(name) || owner_of(name) == hub
23
33
 
@@ -34,7 +44,7 @@ module HubKernel
34
44
  def owner_of_file(path)
35
45
  return owner_of_view_folder(File.dirname(path.delete_prefix("app/views/")).camelize) if path.start_with?("app/views/")
36
46
 
37
- owner_of(path.sub(%r{\Aapp/[^/]+/}, "").delete_suffix(".rb").camelize)
47
+ owner_of(class_of(path))
38
48
  end
39
49
 
40
50
  def owner_of_view_folder(folder) = owner_of("#{folder}Controller") || owner_of(folder) || @host_layer
@@ -1,3 +1,3 @@
1
1
  module HubKernel
2
- VERSION = "0.11.0"
2
+ VERSION = "0.13.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.11.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider