hub_kernel 0.4.0 → 0.6.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 -0
- data/lib/hub_kernel/conformance/hub.rb +22 -0
- data/lib/hub_kernel/exposes.rb +15 -0
- data/lib/hub_kernel/ports.rb +5 -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: 04f59c358a3f035fa56669fe9c6da01ceb7a8e513493ad6ca29b108758510d9c
|
|
4
|
+
data.tar.gz: 47a75f20985cf4ce0291e61e389d421245c93e90a3e04255ed69af769dc18469
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4cbcfba750818bdf25789490618b5959effc5af6a7aaca97daf17a7571162c25c35f452a2b26291ad62b7affaf74fc52a195ba65fbb00129fe09bed16e51f12f
|
|
7
|
+
data.tar.gz: 84909e946aac47038945054c3f8548170417388d4af2f96cef7826460385a49e57dc1bf587df6051d5acec6ab57d7355e91b400f9cba29c0306f1d5dcc988dad
|
data/README.md
CHANGED
|
@@ -44,6 +44,39 @@ It raises `HubKernel::UnwiredPortError` naming every unfilled port with its hub,
|
|
|
44
44
|
line. Running it inside `to_prepare` checks again after every code reload, and a hub
|
|
45
45
|
declared again on a reload stays on the list once.
|
|
46
46
|
|
|
47
|
+
### The hub check
|
|
48
|
+
A hub's own test can check that the app filled every one of its ports, so a missing
|
|
49
|
+
fill shows in the suite rather than on the next start:
|
|
50
|
+
|
|
51
|
+
```ruby
|
|
52
|
+
require "hub_kernel/conformance/hub"
|
|
53
|
+
|
|
54
|
+
class SuppliesHubTest < ActiveSupport::TestCase
|
|
55
|
+
include HubKernel::Conformance::Hub
|
|
56
|
+
|
|
57
|
+
hub { Supplies }
|
|
58
|
+
end
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The test fails and names each port the app left unfilled, and each port filled with
|
|
62
|
+
something that cannot be called.
|
|
63
|
+
|
|
64
|
+
### The exposed list
|
|
65
|
+
A hub names each method outside callers may reach, the values it takes, and whether it
|
|
66
|
+
writes. A layer such as a JSON endpoint looks a method up by name and serves only what
|
|
67
|
+
the hub exposes:
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
module Supplies
|
|
71
|
+
extend HubKernel::Exposes
|
|
72
|
+
|
|
73
|
+
exposes :record_purchase, takes: %i[supplier_id bought_on lines], writes: true
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
Supplies.exposed("record_purchase").takes # => [:supplier_id, :bought_on, :lines]
|
|
77
|
+
Supplies.exposed("delete_everything") # => nil
|
|
78
|
+
```
|
|
79
|
+
|
|
47
80
|
## Installation
|
|
48
81
|
Add this line to your application's Gemfile:
|
|
49
82
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "active_support/concern"
|
|
2
|
+
|
|
3
|
+
module HubKernel
|
|
4
|
+
module Conformance
|
|
5
|
+
module Hub
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
class_methods do
|
|
9
|
+
def hub(&block)
|
|
10
|
+
define_method(:the_hub, &block)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
included do
|
|
15
|
+
test "every port of the hub is filled with something that can be called" do
|
|
16
|
+
problems = the_hub.unwired_ports + the_hub.uncallable_ports
|
|
17
|
+
flunk problems.join("\n") if problems.any?
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
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/ports.rb
CHANGED
|
@@ -17,6 +17,11 @@ module HubKernel
|
|
|
17
17
|
declared_ports.reject { |name| instance_variable_get(:"@#{name}") }.map { |name| unwired_message(name) }
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
def uncallable_ports
|
|
21
|
+
declared_ports.select { |name| instance_variable_get(:"@#{name}")&.respond_to?(:call) == false }
|
|
22
|
+
.map { |name| "#{hub_name} #{name.to_s.tr("_", " ")} is filled with something that cannot be called" }
|
|
23
|
+
end
|
|
24
|
+
|
|
20
25
|
private
|
|
21
26
|
|
|
22
27
|
def declared_ports = @declared_ports ||= []
|
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.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- tylercschneider
|
|
@@ -41,9 +41,11 @@ files:
|
|
|
41
41
|
- lib/hub_kernel/answer.rb
|
|
42
42
|
- lib/hub_kernel/authz.rb
|
|
43
43
|
- lib/hub_kernel/conformance/action.rb
|
|
44
|
+
- lib/hub_kernel/conformance/hub.rb
|
|
44
45
|
- lib/hub_kernel/conformance/partial.rb
|
|
45
46
|
- lib/hub_kernel/context.rb
|
|
46
47
|
- lib/hub_kernel/engine.rb
|
|
48
|
+
- lib/hub_kernel/exposes.rb
|
|
47
49
|
- lib/hub_kernel/follow_up.rb
|
|
48
50
|
- lib/hub_kernel/hubs.rb
|
|
49
51
|
- lib/hub_kernel/markup.rb
|