hub_kernel 0.23.0 → 0.24.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: 62d50b8fc5eef4ade3f013299536de0776ffe8bf0635aa5ffb80ea8518f971aa
4
- data.tar.gz: 955b417a4a57bb859e7991ae6832b4f1c70233d56a30abae5771a729e5b79c05
3
+ metadata.gz: 278e7929cc3994d1e1149a5fa9ce387922748cb829f615e9bf56e52d960f1d06
4
+ data.tar.gz: b60a8992e16825e54d1c8f211e9ce09a814bfe4d0215d94bc40d8da77f74a281
5
5
  SHA512:
6
- metadata.gz: b2707daa5d057cc5fce381bb225af606a62f429651a276d2b6b84d953b0df357b8a51cc9fa142be89c3f1fa79b7e9edd7ac7a0a6d8028248294db0c9478c32fa
7
- data.tar.gz: f2f06d8c9e8cd8c21eb01950e8461fc5eed0474069c595b3b6d7a790f6fea1e9164d8040bf88352623f82e6a7955acfdfb27ace413ddd738d3f94f3b105b1b0e
6
+ metadata.gz: 82a223294f8bbe74427019e44a38ef20678e8d6680d4e384e2c68be6322abe05da574dfa47dca5689d0ee31103ff903f841001906378842ed25aa81f1f6e5310
7
+ data.tar.gz: bb81b8f0de934af592603666605e30349170ac35bd89fe59a6903cf51e62a5e4cf0dc36070dd1dd44d9c201999efddfc46e79c45002698787e3b9015f99c7819
data/README.md CHANGED
@@ -42,6 +42,11 @@ module may be defined in `app/models/` or in another hub's folder. A host with n
42
42
 
43
43
  Files under a hub's `lib/` folder, such as its generated event pack, are not loaded.
44
44
 
45
+ Every hub module in a hub folder, a module that extends `HubKernel::Ports` or
46
+ `HubKernel::Exposes`, is loaded at boot and again after each code reload, before the
47
+ host's own `to_prepare` code runs. A hub the host's code never names is still on
48
+ `HubKernel::Hubs.list` for the start check, and hub_kernel-interface still serves it.
49
+
45
50
  A hub folder's `views` are searched after the host's `app/views`, so a controller in the
46
51
  hub renders its templates from there, any view can render a hub partial by its usual
47
52
  path, and a template in `app/views` wins over one at the same path in a hub folder. A
@@ -3,7 +3,6 @@ require "active_support/core_ext/string/inflections"
3
3
 
4
4
  module HubKernel
5
5
  class Crossings
6
- HUB_MODULE = /extend HubKernel::(Ports|Exposes)\b/
7
6
  def initialize(owners: {}, shared: [], host_layer: nil, interfaces: {}, namespaces: {}, folder_files: [])
8
7
  @owners = owners
9
8
  @folder_classes = {}
@@ -27,7 +26,7 @@ module HubKernel
27
26
 
28
27
  def read_hub_modules(sources)
29
28
  sources.each do |path, source|
30
- next unless source.match?(HUB_MODULE) && path.match?(HubFolders::CODE_PATH)
29
+ next unless HubFolders.hub_module?(path, source)
31
30
 
32
31
  @folder_interfaces[HubFolders.class_of(path)] = HubFolders.hub_of(path)
33
32
  end
@@ -15,5 +15,7 @@ module HubKernel
15
15
  views = HubFolders.view_paths(app.root)
16
16
  ActiveSupport.on_load(:action_controller) { append_view_path(views) }
17
17
  end
18
+
19
+ config.to_prepare { HubFolders.hub_modules(Rails.root).each(&:constantize) }
18
20
  end
19
21
  end
@@ -7,6 +7,7 @@ module HubKernel
7
7
 
8
8
  PATH = %r{\A#{ROOT}/([^/]+)/}
9
9
  CODE_PATH = %r{\A#{ROOT}/[^/]+/#{CODE}/[^/]+/}
10
+ HUB_MODULE = /extend HubKernel::(Ports|Exposes)\b/
10
11
 
11
12
  def self.folder(hub) = "#{ROOT}/#{hub}"
12
13
 
@@ -24,6 +25,12 @@ module HubKernel
24
25
 
25
26
  def self.helper_paths(root) = Dir[root.join("#{code_glob}/helpers")]
26
27
 
28
+ def self.hub_module?(path, source) = source.match?(HUB_MODULE) && path.match?(CODE_PATH)
29
+
30
+ def self.hub_modules(root)
31
+ Dir.glob("#{code_glob}/**/*.rb", base: root).select { |path| hub_module?(path, root.join(path).read) }.map { |path| class_of(path) }
32
+ end
33
+
27
34
  def self.hub_of_controller(root, page)
28
35
  controllers = Dir[root.join(code_glob, "controllers", "#{page}_controller.rb").to_s].sort
29
36
  hubs = controllers.map { |controller| hub_of(Pathname(controller).relative_path_from(root).to_s) }
@@ -3,15 +3,21 @@ module HubKernel
3
3
  private
4
4
 
5
5
  def saved(record)
6
- record.save ? record.id : refuse(record)
6
+ record.save ? record.id : refuse(record, "saved")
7
7
  end
8
8
 
9
9
  def removed(record)
10
- record.destroy ? record.id : refuse(record)
10
+ record.destroy ? record.id : refuse(record, "deleted")
11
11
  end
12
12
 
13
- def refuse(record)
14
- raise Refused, record.errors.full_messages.to_sentence
13
+ def refuse(record, action)
14
+ raise Refused, refusal(record, action)
15
+ end
16
+
17
+ def refusal(record, action)
18
+ return record.errors.full_messages.to_sentence if record.errors.any?
19
+
20
+ "#{record.model_name.human} could not be #{action}"
15
21
  end
16
22
  end
17
23
  end
@@ -1,3 +1,3 @@
1
1
  module HubKernel
2
- VERSION = "0.23.0"
2
+ VERSION = "0.24.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.23.0
4
+ version: 0.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider