hub_kernel 0.7.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: 03e711745ec2a1b5caccf83f09e80cad02ba4214cc7eff72745c2a6d760e175e
4
- data.tar.gz: f3bc9c33cd2f1ae4878f9cb9dd2216ebda64c2c3628f7d1a29794dee4f10ef11
3
+ metadata.gz: a20cf973f68397694b8434e58918a40c31619eb8936aad87f8a183122aad47f4
4
+ data.tar.gz: 38a563f62a0c9bf630e72823b94c5cdba0cfe71bfe8c54d45d00a7129e8b5f32
5
5
  SHA512:
6
- metadata.gz: 443d578d53ebb20b08fb3e3c3557df70780f8f85e8aab44af99c68ee6f3311897649210b544ba6356b4d1e7a1692576e36e84c36daed045ab2d47270ddc69b2c
7
- data.tar.gz: 833fba7864e95ad4ff7e18284bd07998f7ff30df5269489c879a447541e207997ebeb09d2dafad1596aa0299c7a05259d2e997682c6b5edffe490772f405a061
6
+ metadata.gz: 13453ee9d42aa2ac1fe4d3e95ad216867f27d9d2b13f9e71cfa52fe244add5f32e7dbb1a43912af43aba99fa060f3d564746265bb5e973ab4064399beb01e7bd
7
+ data.tar.gz: c55bce27f9ef2d71959cf39102a38a0c8b471f1d35665fedfa16c3325e96d2676cef36dc57f90c8da167cdfdd64d9bd248b029edf496f60f4e471b1d11e798f1
data/README.md CHANGED
@@ -4,16 +4,43 @@ Gives every hub in a Rails app one way to declare what it needs from another hub
4
4
  ## Usage
5
5
 
6
6
  ### Starting a hub
7
- The generator writes a new hub's module and its test. Name each port as the port and
8
- the method the hub's own code calls:
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:
9
10
 
10
11
  ```bash
11
- bin/rails generate hub_kernel:hub Console::Hubs::Billing spend_recorder:record_spend
12
+ bin/rails generate hub_kernel:hub Ledger entry_recorder:record_entry
12
13
  ```
13
14
 
14
- It writes `app/models/console/hubs/billing.rb`, which extends `HubKernel::Ports` and
15
- declares each port, and `test/models/console/hubs/billing_test.rb`, which includes the
16
- hub check below. The app then fills the new ports where it fills its others.
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`.
17
44
 
18
45
  ### Ports
19
46
  A port is something a hub needs from outside itself. The hub declares it by name,
@@ -14,6 +14,8 @@ module HubKernel
14
14
  end
15
15
 
16
16
  def create_hub_test
17
+ return if gemspec
18
+
17
19
  create_file "test/models/#{file_path}_test.rb", <<~RUBY
18
20
  require "test_helper"
19
21
  require "hub_kernel/conformance/hub"
@@ -26,8 +28,16 @@ module HubKernel
26
28
  RUBY
27
29
  end
28
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
+
29
37
  private
30
38
 
39
+ def gemspec = Dir.glob("*.gemspec", base: destination_root).first
40
+
31
41
  def port_lines
32
42
  return "" if ports.empty?
33
43
 
@@ -1,3 +1,3 @@
1
1
  module HubKernel
2
- VERSION = "0.7.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.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider