hub_kernel-interface 0.8.0 → 0.10.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: d0080a27457d5f374c3c92fbbeeecbd3ad8e1c6543e2274634cb14df708626c0
4
- data.tar.gz: 76609fd82439a9b52510439ab93ed23d81f222edd14a3aa9f2d3276a5bc7aa76
3
+ metadata.gz: a110bf3b15c7fbe91d280d688cadadb134e3e2ab7bbf2ef513d56b23ccbb94d6
4
+ data.tar.gz: eed0d2ced815810fb69566fcf8d23782855a9034c5ff4e9d498c9b18c82ca165
5
5
  SHA512:
6
- metadata.gz: 1c9820a93999b13cf6895dc4b5a10622210aa656b9ec078650790886079dee7a149f507e47c973275e7ab41ceb375e08f0d5fa8246dc62ad39f02f8a84811af0
7
- data.tar.gz: 7c9f45f51ebac824991737b2170e48c7665788d5ed30d4f3d2f98b6bd5db820e1fa2afa278abc48e7bc9d10ab8bcfe8d01644823d5682bd6f74dde37dc8fe16b
6
+ metadata.gz: ce020e02f3fb14ac881793f935ddb4f2e25f5f9a848da3c15a7ebb8e64a285dcda66f235fe19bcda4fee37316e0d34bc00cbb191de458f08c890083644a6190c
7
+ data.tar.gz: e3468ec19dc532b3a6092084f9e7bb07d20a78072679f86976a946be4dd2ad439d4934add1168d2338a28b450659910f6ccd8a06c425ce3f72214c326a72f316
data/README.md CHANGED
@@ -40,9 +40,11 @@ for a missing person, account or required value. A hub refuses with `HubKernel::
40
40
  reason a person can read. A call made while the permission check or the account scope is unset
41
41
  raises `HubKernel::UnwiredPortError`.
42
42
 
43
- The host names the hubs every interface serves, once. A hub listed alone is served at its
43
+ Every interface serves every hub that exposes a method, each at its module name in snake
44
+ case, unless the host names the hubs to serve, once. A hub listed alone is served at its
44
45
  module name in snake case, and a hub listed as a one-pair hash is served only at the name
45
- given. An interface gem finds the hub served at a name, or `nil` when none is:
46
+ given. Setting the list to `nil` serves every exposing hub again. An interface gem finds the
47
+ hub served at a name, or `nil` when none is:
46
48
 
47
49
  ```ruby
48
50
  HubKernel::Interface.hubs = [ Supplies, { "money" => Billing::Ledger } ]
@@ -55,6 +57,14 @@ HubKernel::Interface.served # => { "supplies" => Supplies, "money" =>
55
57
  The permission check is still asked about a hub served under a chosen name by its own name,
56
58
  such as `ledger:record_spend`.
57
59
 
60
+ The host names the methods that give the calling person and account once, here, for an
61
+ interface gem to read:
62
+
63
+ ```ruby
64
+ HubKernel::Interface.person_method = :hub_person
65
+ HubKernel::Interface.account_method = :hub_account
66
+ ```
67
+
58
68
  An interface gem's boot check runs `HubKernel::Interface.check!`, which raises
59
69
  `HubKernel::Interface::UnservableHubError` naming every problem in the served list at once:
60
70
  an entry that exposes no methods, two entries that answer at the same name, and each
@@ -12,11 +12,16 @@ module HubKernel
12
12
  class Refused < StandardError; end
13
13
 
14
14
  module Exposes
15
- Exposed = Data.define(:name, :takes, :writes)
15
+ Exposed = Data.define(:name, :takes, :writes, :earlier_answers, :answer_shape) do
16
+ def earlier_answer(major) = earlier_answers.find { |earlier| earlier.major == major }
17
+ end
18
+ EarlierAnswer = Data.define(:major, :translation, :answer_shape) do
19
+ def translate(answer) = translation.call(answer)
20
+ end
16
21
 
17
- def exposes(name, takes:, writes:)
22
+ def exposes(name, takes:, writes:, earlier_answers: {}, answer_shape: nil)
18
23
  Interface::ExposingHubs.add(self)
19
- exposed_methods[name.to_s] = Exposed.new(name: name, takes: takes, writes: writes)
24
+ exposed_methods[name.to_s] = Exposed.new(name: name, takes: takes, writes: writes, earlier_answers: earlier_answers.map { |major, declared| earlier_answer_from(major, declared) }, answer_shape: answer_shape)
20
25
  end
21
26
 
22
27
  def exposed(name) = exposed_methods[name.to_s]
@@ -54,6 +59,12 @@ module HubKernel
54
59
 
55
60
  def exposing_hub = name.demodulize
56
61
 
62
+ def earlier_answer_from(major, declared)
63
+ return EarlierAnswer.new(major: major, translation: declared, answer_shape: nil) if declared.respond_to?(:call)
64
+
65
+ EarlierAnswer.new(major: major, translation: declared[:translation], answer_shape: declared[:answer_shape])
66
+ end
67
+
57
68
  def refuse_without_caller(person, account)
58
69
  raise MissingArgumentError, "A call by name needs a person" if person.nil?
59
70
  raise MissingArgumentError, "A call by name needs an account" if account.nil?
@@ -1,5 +1,5 @@
1
1
  module HubKernel
2
2
  module Interface
3
- VERSION = "0.8.0"
3
+ VERSION = "0.10.0"
4
4
  end
5
5
  end
@@ -2,6 +2,7 @@ require "hub_kernel/interface/version"
2
2
  require "hub_kernel/interface/hub_kernel_release"
3
3
  HubKernel::Interface::HubKernelRelease.refuse_older!(Gem.loaded_specs["hub_kernel"])
4
4
  require "hub_kernel/exposes"
5
+ require "hub_kernel/interface/exposing_hubs"
5
6
  require "hub_kernel/interface/call_reasons"
6
7
 
7
8
  module HubKernel
@@ -9,8 +10,9 @@ module HubKernel
9
10
  class UnservableHubError < StandardError; end
10
11
 
11
12
  singleton_class.attr_writer :hubs
13
+ singleton_class.attr_accessor :person_method, :account_method
12
14
 
13
- def self.hubs = @hubs ||= []
15
+ def self.hubs = @hubs || ExposingHubs.list.dup
14
16
 
15
17
  def self.find(name) = served[name]
16
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hub_kernel-interface
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider