hub_kernel 0.11.0 → 0.12.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: 229fcc87e3137795f02b73e3f0be126e9809181b14446e09e8a1a050fa83420e
4
+ data.tar.gz: 2347fa14b7911dda34f7e1cbebb924eb10f99f8da0e5e086f112f78aa79440b9
5
5
  SHA512:
6
- metadata.gz: e5d72c62b32c671f49ae4babcc4755dd871fc4fcfaa35573c78689250ca6b27774bb9ce2db460405940774fc017d1abd742da4df1d646565f8df770d379deb00
7
- data.tar.gz: 4d5dff84ef2be0d5ebc3a53ce43e22e42d5d73ad53b0601663139f3fc0a68876e8c874a1833c200d078b29684d0bcd4056f11dd84150c0181dc6462943e9262a
6
+ metadata.gz: e432500a7d6b4dc4c0e7a4061d74dfc81108435a640d4098afaa0a9ca58518790b75d94ba5e5d49e28c87e88925a1b6369f36968cc5b9fafb31480034730ecde
7
+ data.tar.gz: fbf852ad51486ad330f5b7b0cefa7f36d599c7c713a0a95e2cffcbd689e41ea0042550a00e24c66a19778507e32ff992001aa90828ea10f6c8ed2d4f6d74f644
data/README.md CHANGED
@@ -196,6 +196,9 @@ 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".
199
202
 
200
203
  ## Installation
201
204
  Add this line to your application's Gemfile:
@@ -17,15 +17,26 @@ 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
28
37
  end
38
+
39
+ def crossing_paths = (Dir.glob(crossing_files, base: crossing_root) - crossing_exceptions).sort
29
40
  end
30
41
  end
31
42
  end
@@ -16,8 +16,16 @@ 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
+
19
25
  private
20
26
 
27
+ def class_of(path) = path.sub(%r{\Aapp/[^/]+/}, "").delete_suffix(".rb").camelize
28
+
21
29
  def crossing?(name, hub)
22
30
  return false if @shared.include?(name) || owner_of(name) == hub
23
31
 
@@ -34,7 +42,7 @@ module HubKernel
34
42
  def owner_of_file(path)
35
43
  return owner_of_view_folder(File.dirname(path.delete_prefix("app/views/")).camelize) if path.start_with?("app/views/")
36
44
 
37
- owner_of(path.sub(%r{\Aapp/[^/]+/}, "").delete_suffix(".rb").camelize)
45
+ owner_of(class_of(path))
38
46
  end
39
47
 
40
48
  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.12.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.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider