hub_kernel 0.22.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: fa846ab97d20c75f7e3dd54468262589d42a134aa487f54e4a54216861d73a2f
4
- data.tar.gz: 2e85a76639b5cb385446786265d99f73be3fac6a701da33e038f49e8ae85b8df
3
+ metadata.gz: 278e7929cc3994d1e1149a5fa9ce387922748cb829f615e9bf56e52d960f1d06
4
+ data.tar.gz: b60a8992e16825e54d1c8f211e9ce09a814bfe4d0215d94bc40d8da77f74a281
5
5
  SHA512:
6
- metadata.gz: 710c5a3a33ccbba307e5c2cc2327a329de79055dc6f8519f062b33cb3c15d154a458081461e7a72be2ab668bea993baee8804d8730f7b2771cd536e6c5207c54
7
- data.tar.gz: 9db5be35d6a50094db6bf76811830b21308fcce941c86caaa4d6bc72adc36583441633a985f07cbea95a00ec895d0f84fdfc71266c1f210bd66b3400ade814d6
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
@@ -1,10 +1,13 @@
1
1
  module HubKernel
2
2
  module HubFolders
3
+ class SharedController < StandardError; end
4
+
3
5
  ROOT = "hubs".freeze
4
6
  CODE = "app".freeze
5
7
 
6
8
  PATH = %r{\A#{ROOT}/([^/]+)/}
7
9
  CODE_PATH = %r{\A#{ROOT}/[^/]+/#{CODE}/[^/]+/}
10
+ HUB_MODULE = /extend HubKernel::(Ports|Exposes)\b/
8
11
 
9
12
  def self.folder(hub) = "#{ROOT}/#{hub}"
10
13
 
@@ -21,5 +24,19 @@ module HubKernel
21
24
  def self.view_paths(root) = Dir[root.join("#{code_glob}/views")]
22
25
 
23
26
  def self.helper_paths(root) = Dir[root.join("#{code_glob}/helpers")]
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
+
34
+ def self.hub_of_controller(root, page)
35
+ controllers = Dir[root.join(code_glob, "controllers", "#{page}_controller.rb").to_s].sort
36
+ hubs = controllers.map { |controller| hub_of(Pathname(controller).relative_path_from(root).to_s) }
37
+ raise SharedController, "#{page}_controller.rb is in more than one hub folder: #{hubs.map { |hub| folder(hub) }.join(", ")}" if hubs.many?
38
+
39
+ hubs.first
40
+ end
24
41
  end
25
42
  end
@@ -0,0 +1,24 @@
1
+ require "active_support/concern"
2
+
3
+ module HubKernel
4
+ module KeptPorts
5
+ extend ActiveSupport::Concern
6
+
7
+ class_methods do
8
+ def keep_ports(&block)
9
+ define_method(:hubs_with_kept_ports) { Array(instance_exec(&block)) }
10
+ end
11
+ end
12
+
13
+ included do
14
+ setup { @kept_ports = hubs_with_kept_ports.to_h { |hub| [ hub, fillings_of(hub) ] } }
15
+ teardown { @kept_ports.each { |hub, fillings| fillings.each { |port, filling| hub.public_send(:"#{port}=", filling) } } }
16
+ end
17
+
18
+ private
19
+
20
+ def hubs_with_kept_ports = [ the_hub ]
21
+
22
+ def fillings_of(hub) = hub.port_names.to_h { |port| [ port, hub.instance_variable_get(:"@#{port}") ] }
23
+ end
24
+ end
@@ -13,6 +13,8 @@ module HubKernel
13
13
  define_singleton_method(as) { |*args, **options| public_send(name).call(*args, **options) }
14
14
  end
15
15
 
16
+ def port_names = declared_ports.dup
17
+
16
18
  def unwired_ports
17
19
  declared_ports.reject { |name| instance_variable_get(:"@#{name}") }.map { |name| unwired_message(name) }
18
20
  end
@@ -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.22.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.22.0
4
+ version: 0.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider
@@ -64,6 +64,7 @@ files:
64
64
  - lib/hub_kernel/follow_up.rb
65
65
  - lib/hub_kernel/hub_folders.rb
66
66
  - lib/hub_kernel/hubs.rb
67
+ - lib/hub_kernel/kept_ports.rb
67
68
  - lib/hub_kernel/markup.rb
68
69
  - lib/hub_kernel/ports.rb
69
70
  - lib/hub_kernel/records.rb