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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b68695ef96166801769081d8d607907cc32e6d215f798b6404dc8b13a1faab2
4
- data.tar.gz: 2fb12e7fa8b2cf1e8246eea5204ae7b38f61c6b41e668e07c753e7f55f899bf1
3
+ metadata.gz: 04f59c358a3f035fa56669fe9c6da01ceb7a8e513493ad6ca29b108758510d9c
4
+ data.tar.gz: 47a75f20985cf4ce0291e61e389d421245c93e90a3e04255ed69af769dc18469
5
5
  SHA512:
6
- metadata.gz: 4cecfcff2e7565d73b3c047ff191cc57a1f1f73056727a644a82bcc6f07517678d370c8876abb7c6c97e10197d663d2f0fa046a1430939e38583a5e89dda7f7f
7
- data.tar.gz: 7a83ad99b5cc838650469b8e436d6a8a7f3d70e2ac37685206e1a1094f98c987dde0b29044b52dc5def44b2392e2b3eb045332819bbe160581c028c27ae7df36
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
@@ -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 ||= []
@@ -1,3 +1,3 @@
1
1
  module HubKernel
2
- VERSION = "0.4.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/hub_kernel.rb CHANGED
@@ -5,6 +5,7 @@ require "hub_kernel/answer"
5
5
  require "hub_kernel/follow_up"
6
6
  require "hub_kernel/markup"
7
7
  require "hub_kernel/ports"
8
+ require "hub_kernel/exposes"
8
9
 
9
10
  module HubKernel
10
11
  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.4.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