hub_kernel-interface 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: 9385ca6b5908cfc7854200c351dd6f6cbe30a90c850d14a7519c4e73a5d2eeeb
4
- data.tar.gz: 199574b3bc71a071a97670a97dd8ab08747945b45216d1eac24d21f22ffa965a
3
+ metadata.gz: 46efe9234db5355c30fb8e4860fb8183028c7d41fb5e4ca4172d5f939bf0aee8
4
+ data.tar.gz: a0108815b76bd611f424978603340d9c1901d8e5d0632e78f1482dc9109a0747
5
5
  SHA512:
6
- metadata.gz: 96ef67da95a65e5fd1f26c3fc6ef25e9ad0a9fb28a742b03ce2399aefb5360ccddcb4c764c04a2255b685b542a1d612937163b252b47ee7c2eb7cc2888688618
7
- data.tar.gz: e36173e0a4b7f957323969718216df7c7c0ca5083ba1852ac094c77d75579b9da986e64c8c11c996e4efb139379d77a08862b773f557820f0b1f13532df09fc3
6
+ metadata.gz: 4366f0048a51612e55228f972bc76311ca69283b7e04ea22c463bcd3ae6a049d943f989b559ea25c9d69070f3afaaf2cfc5986afb46cd0e6c4094f5ee42b4d19
7
+ data.tar.gz: 7ad825094966140dccefbc112ace422d68986a6d6707ac7116fede8a215e3bf4bfce0250335c5efd773a4d39d9472b33ae27a15eb835ff8097828c236d015789
data/README.md CHANGED
@@ -60,6 +60,22 @@ An interface gem's boot check runs `HubKernel::Interface.check!`, which raises
60
60
  an entry that exposes no methods, two entries that answer at the same name, and each
61
61
  problem in a served hub's exposed list.
62
62
 
63
+ An interface gem checks a call's values before calling, and describes a record the call
64
+ named that does not exist, so every interface gives the same reasons:
65
+
66
+ ```ruby
67
+ HubKernel::Interface::CallReasons.refuse_unlisted_values(Supplies, "price_of", values: values, person: person, account: account)
68
+ HubKernel::Interface::CallReasons.missing_record(error) # => "No consumable has the id 7"
69
+ ```
70
+
71
+ `refuse_unlisted_values` does nothing for a call that sends only listed values, and asks the
72
+ permission check nothing. For a call that sends any other value, it asks the permission check
73
+ once about the called method, raises `HubKernel::NotAllowed` when it refuses, and otherwise
74
+ raises `HubKernel::Refused` naming the method and every value it is not listed with.
75
+
76
+ `Supplies.allows?("price_of", person: person, account: account)` asks the permission check
77
+ about that one method. `missing_record` reads the error's `model` and `id`.
78
+
63
79
  `Supplies.exposure_problems` names each exposed method the hub has no method for, or lists
64
80
  with values it does not take. `HubKernel::Interface::ExposingHubs.list` holds every hub that
65
81
  declares an exposed method.
@@ -29,6 +29,12 @@ module HubKernel
29
29
  exposures.select { |exposure| allowed?(exposure, person, account) }
30
30
  end
31
31
 
32
+ def allows?(name, person:, account:)
33
+ refuse_without_caller(person, account)
34
+
35
+ allowed?(exposed(name), person, account)
36
+ end
37
+
32
38
  def call_exposed(name, values:, person:, account:)
33
39
  refuse_without_caller(person, account)
34
40
 
@@ -0,0 +1,17 @@
1
+ require "hub_kernel/exposes"
2
+
3
+ module HubKernel
4
+ module Interface
5
+ module CallReasons
6
+ def self.refuse_unlisted_values(hub, name, values:, person:, account:)
7
+ unlisted = values.keys - hub.exposed(name).takes
8
+ return if unlisted.none?
9
+
10
+ raise HubKernel::NotAllowed, "#{hub.name.demodulize} #{name}" unless hub.allows?(name, person: person, account: account)
11
+ raise HubKernel::Refused, "#{name} does not take #{unlisted.join(", ")}" if unlisted.any?
12
+ end
13
+
14
+ def self.missing_record(missing) = "No #{missing.model.demodulize.underscore.humanize(capitalize: false)} has the id #{missing.id}"
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  module HubKernel
2
2
  module Interface
3
- VERSION = "0.4.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  require "hub_kernel/interface/version"
2
2
  require "hub_kernel/exposes"
3
+ require "hub_kernel/interface/call_reasons"
3
4
 
4
5
  module HubKernel
5
6
  module Interface
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.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider
@@ -40,6 +40,7 @@ files:
40
40
  - lib/hub_kernel/context.rb
41
41
  - lib/hub_kernel/exposes.rb
42
42
  - lib/hub_kernel/interface.rb
43
+ - lib/hub_kernel/interface/call_reasons.rb
43
44
  - lib/hub_kernel/interface/exposing_hubs.rb
44
45
  - lib/hub_kernel/interface/version.rb
45
46
  homepage: https://github.com/DYB-Development/hub_kernel-interface