hub_kernel 0.5.0 → 0.7.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 +28 -0
- data/lib/generators/hub_kernel/hub/hub_generator.rb +38 -0
- data/lib/hub_kernel/exposes.rb +15 -0
- data/lib/hub_kernel/version.rb +1 -1
- data/lib/hub_kernel.rb +1 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 03e711745ec2a1b5caccf83f09e80cad02ba4214cc7eff72745c2a6d760e175e
|
|
4
|
+
data.tar.gz: f3bc9c33cd2f1ae4878f9cb9dd2216ebda64c2c3628f7d1a29794dee4f10ef11
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 443d578d53ebb20b08fb3e3c3557df70780f8f85e8aab44af99c68ee6f3311897649210b544ba6356b4d1e7a1692576e36e84c36daed045ab2d47270ddc69b2c
|
|
7
|
+
data.tar.gz: 833fba7864e95ad4ff7e18284bd07998f7ff30df5269489c879a447541e207997ebeb09d2dafad1596aa0299c7a05259d2e997682c6b5edffe490772f405a061
|
data/README.md
CHANGED
|
@@ -3,6 +3,18 @@ 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
|
+
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:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
bin/rails generate hub_kernel:hub Console::Hubs::Billing spend_recorder:record_spend
|
|
12
|
+
```
|
|
13
|
+
|
|
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.
|
|
17
|
+
|
|
6
18
|
### Ports
|
|
7
19
|
A port is something a hub needs from outside itself. The hub declares it by name,
|
|
8
20
|
with the method its own code calls:
|
|
@@ -61,6 +73,22 @@ end
|
|
|
61
73
|
The test fails and names each port the app left unfilled, and each port filled with
|
|
62
74
|
something that cannot be called.
|
|
63
75
|
|
|
76
|
+
### The exposed list
|
|
77
|
+
A hub names each method outside callers may reach, the values it takes, and whether it
|
|
78
|
+
writes. A layer such as a JSON endpoint looks a method up by name and serves only what
|
|
79
|
+
the hub exposes:
|
|
80
|
+
|
|
81
|
+
```ruby
|
|
82
|
+
module Supplies
|
|
83
|
+
extend HubKernel::Exposes
|
|
84
|
+
|
|
85
|
+
exposes :record_purchase, takes: %i[supplier_id bought_on lines], writes: true
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
Supplies.exposed("record_purchase").takes # => [:supplier_id, :bought_on, :lines]
|
|
89
|
+
Supplies.exposed("delete_everything") # => nil
|
|
90
|
+
```
|
|
91
|
+
|
|
64
92
|
## Installation
|
|
65
93
|
Add this line to your application's Gemfile:
|
|
66
94
|
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
create_file "test/models/#{file_path}_test.rb", <<~RUBY
|
|
18
|
+
require "test_helper"
|
|
19
|
+
require "hub_kernel/conformance/hub"
|
|
20
|
+
|
|
21
|
+
class #{class_name}Test < ActiveSupport::TestCase
|
|
22
|
+
include HubKernel::Conformance::Hub
|
|
23
|
+
|
|
24
|
+
hub { #{class_name} }
|
|
25
|
+
end
|
|
26
|
+
RUBY
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def port_lines
|
|
32
|
+
return "" if ports.empty?
|
|
33
|
+
|
|
34
|
+
"\n" + ports.map { |pair| pair.split(":") }.map { |port, method| " port :#{port}, as: :#{method}\n" }.join
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module HubKernel
|
|
2
|
+
module Exposes
|
|
3
|
+
Exposed = Data.define(:name, :takes, :writes)
|
|
4
|
+
|
|
5
|
+
def exposes(name, takes:, writes:)
|
|
6
|
+
exposed_methods[name.to_s] = Exposed.new(name: name, takes: takes, writes: writes)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def exposed(name) = exposed_methods[name.to_s]
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def exposed_methods = @exposed_methods ||= {}
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/hub_kernel/version.rb
CHANGED
data/lib/hub_kernel.rb
CHANGED
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.
|
|
4
|
+
version: 0.7.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
|
|
@@ -45,6 +46,7 @@ files:
|
|
|
45
46
|
- lib/hub_kernel/conformance/partial.rb
|
|
46
47
|
- lib/hub_kernel/context.rb
|
|
47
48
|
- lib/hub_kernel/engine.rb
|
|
49
|
+
- lib/hub_kernel/exposes.rb
|
|
48
50
|
- lib/hub_kernel/follow_up.rb
|
|
49
51
|
- lib/hub_kernel/hubs.rb
|
|
50
52
|
- lib/hub_kernel/markup.rb
|