hub_kernel-interface 0.4.0 → 0.5.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: b0fa91bb8d315c37de4f4d2aadb2c12e924b092b763b2d932eecf0a0adb161d8
4
+ data.tar.gz: bccf1208493a973a64cb76df47226cd638d375aa38e3dfa34f18e801a4fba94f
5
5
  SHA512:
6
- metadata.gz: 96ef67da95a65e5fd1f26c3fc6ef25e9ad0a9fb28a742b03ce2399aefb5360ccddcb4c764c04a2255b685b542a1d612937163b252b47ee7c2eb7cc2888688618
7
- data.tar.gz: e36173e0a4b7f957323969718216df7c7c0ca5083ba1852ac094c77d75579b9da986e64c8c11c996e4efb139379d77a08862b773f557820f0b1f13532df09fc3
6
+ metadata.gz: 2114bad113c0a16a3f6a85b59a01f887928980fa69f334e32dcdb19f5ca7ac1397c234d67779d8c5ba275c794254cbb673a6fc3db5f5b2fb6c0d35858acc587c
7
+ data.tar.gz: 90e57ae0a730030c16c895f94d6011c99d371bb7443668e935c681b95f1a58b0de8440bc0bf011f6b5110583b173100bfae214241215afe5f9ad0b3783b75d7a
data/README.md CHANGED
@@ -60,6 +60,18 @@ 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` raises `HubKernel::NotAllowed` when the permission check refuses the
72
+ call, whatever values it sends, and otherwise raises `HubKernel::Refused` naming the method and
73
+ every value it is not listed with. `missing_record` reads the error's `model` and `id`.
74
+
63
75
  `Supplies.exposure_problems` names each exposed method the hub has no method for, or lists
64
76
  with values it does not take. `HubKernel::Interface::ExposingHubs.list` holds every hub that
65
77
  declares an exposed method.
@@ -0,0 +1,16 @@
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
+ raise HubKernel::NotAllowed, "#{hub.name.demodulize} #{name}" unless hub.exposures_for(person: person, account: account).any? { |exposure| exposure.name.to_s == name.to_s }
8
+
9
+ unlisted = values.keys - hub.exposed(name).takes
10
+ raise HubKernel::Refused, "#{name} does not take #{unlisted.join(", ")}" if unlisted.any?
11
+ end
12
+
13
+ def self.missing_record(missing) = "No #{missing.model.demodulize.underscore.humanize(capitalize: false)} has the id #{missing.id}"
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  module HubKernel
2
2
  module Interface
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.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.5.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