hub_kernel 0.6.0 → 0.8.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: 04f59c358a3f035fa56669fe9c6da01ceb7a8e513493ad6ca29b108758510d9c
4
- data.tar.gz: 47a75f20985cf4ce0291e61e389d421245c93e90a3e04255ed69af769dc18469
3
+ metadata.gz: a20cf973f68397694b8434e58918a40c31619eb8936aad87f8a183122aad47f4
4
+ data.tar.gz: 38a563f62a0c9bf630e72823b94c5cdba0cfe71bfe8c54d45d00a7129e8b5f32
5
5
  SHA512:
6
- metadata.gz: 4cbcfba750818bdf25789490618b5959effc5af6a7aaca97daf17a7571162c25c35f452a2b26291ad62b7affaf74fc52a195ba65fbb00129fe09bed16e51f12f
7
- data.tar.gz: 84909e946aac47038945054c3f8548170417388d4af2f96cef7826460385a49e57dc1bf587df6051d5acec6ab57d7355e91b400f9cba29c0306f1d5dcc988dad
6
+ metadata.gz: 13453ee9d42aa2ac1fe4d3e95ad216867f27d9d2b13f9e71cfa52fe244add5f32e7dbb1a43912af43aba99fa060f3d564746265bb5e973ab4064399beb01e7bd
7
+ data.tar.gz: c55bce27f9ef2d71959cf39102a38a0c8b471f1d35665fedfa16c3325e96d2676cef36dc57f90c8da167cdfdd64d9bd248b029edf496f60f4e471b1d11e798f1
data/README.md CHANGED
@@ -3,6 +3,45 @@ Gives every hub in a Rails app one way to declare what it needs from another hub
3
3
 
4
4
  ## Usage
5
5
 
6
+ ### Starting a hub
7
+ A hub usually lives in a domain gem, next to the domain logic it serves. Run the
8
+ generator from the gem's root, naming each port as the port and the method the hub's
9
+ own code calls:
10
+
11
+ ```bash
12
+ bin/rails generate hub_kernel:hub Ledger entry_recorder:record_entry
13
+ ```
14
+
15
+ Inside a Rails engine gem it writes the hub under the gem's namespace, such as
16
+ `app/models/billing/ledger.rb` with `module Billing::Ledger`, which extends
17
+ `HubKernel::Ports` and declares each port. It also adds hub_kernel to the gem's
18
+ gemspec. It writes no hub check into the gem's tests, since the gem never fills its own
19
+ ports.
20
+
21
+ ### Using a hub from a gem
22
+ The app that installs the gem fills each of the hub's ports in its own setup, then
23
+ runs the start check:
24
+
25
+ ```ruby
26
+ Rails.application.config.to_prepare do
27
+ Billing::Ledger.entry_recorder = Finance.method(:record_entry)
28
+ HubKernel::Hubs.check!
29
+ end
30
+ ```
31
+
32
+ The app's own test for that hub includes the hub check, where the ports are filled:
33
+
34
+ ```ruby
35
+ class Billing::LedgerHubTest < ActiveSupport::TestCase
36
+ include HubKernel::Conformance::Hub
37
+
38
+ hub { Billing::Ledger }
39
+ end
40
+ ```
41
+
42
+ Run inside an app rather than a gem, the generator writes the hub under
43
+ `app/models` and its hub check under `test/models`.
44
+
6
45
  ### Ports
7
46
  A port is something a hub needs from outside itself. The hub declares it by name,
8
47
  with the method its own code calls:
@@ -0,0 +1,48 @@
1
+ require "rails/generators/named_base"
2
+
3
+ module HubKernel
4
+ module Generators
5
+ class HubGenerator < Rails::Generators::NamedBase
6
+ argument :ports, type: :array, default: [], banner: "port:method port:method"
7
+
8
+ def create_hub
9
+ create_file "app/models/#{file_path}.rb", <<~RUBY
10
+ module #{class_name}
11
+ extend HubKernel::Ports
12
+ #{port_lines}end
13
+ RUBY
14
+ end
15
+
16
+ def create_hub_test
17
+ return if gemspec
18
+
19
+ create_file "test/models/#{file_path}_test.rb", <<~RUBY
20
+ require "test_helper"
21
+ require "hub_kernel/conformance/hub"
22
+
23
+ class #{class_name}Test < ActiveSupport::TestCase
24
+ include HubKernel::Conformance::Hub
25
+
26
+ hub { #{class_name} }
27
+ end
28
+ RUBY
29
+ end
30
+
31
+ def depend_on_hub_kernel
32
+ return unless gemspec
33
+
34
+ inject_into_file gemspec, " spec.add_dependency \"hub_kernel\", \"~> #{HubKernel::VERSION[/\A\d+\.\d+/]}\"\n", before: /^end\s*\z/
35
+ end
36
+
37
+ private
38
+
39
+ def gemspec = Dir.glob("*.gemspec", base: destination_root).first
40
+
41
+ def port_lines
42
+ return "" if ports.empty?
43
+
44
+ "\n" + ports.map { |pair| pair.split(":") }.map { |port, method| " port :#{port}, as: :#{method}\n" }.join
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module HubKernel
2
- VERSION = "0.6.0"
2
+ VERSION = "0.8.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.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider
@@ -36,6 +36,7 @@ files:
36
36
  - README.md
37
37
  - Rakefile
38
38
  - config/routes.rb
39
+ - lib/generators/hub_kernel/hub/hub_generator.rb
39
40
  - lib/hub_kernel.rb
40
41
  - lib/hub_kernel/action.rb
41
42
  - lib/hub_kernel/answer.rb