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 +4 -4
- data/README.md +33 -6
- data/lib/generators/hub_kernel/hub/hub_generator.rb +10 -0
- data/lib/hub_kernel/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a20cf973f68397694b8434e58918a40c31619eb8936aad87f8a183122aad47f4
|
|
4
|
+
data.tar.gz: 38a563f62a0c9bf630e72823b94c5cdba0cfe71bfe8c54d45d00a7129e8b5f32
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
8
|
-
the method the hub's
|
|
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
|
|
12
|
+
bin/rails generate hub_kernel:hub Ledger entry_recorder:record_entry
|
|
12
13
|
```
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
data/lib/hub_kernel/version.rb
CHANGED