Module: Petticoat::Schema
- Defined in:
- lib/petticoat/schema.rb
Constant Summary collapse
- PATH =
File.('schema.json', __dir__).freeze
Class Method Summary collapse
- .validate!(payload) ⇒ Object
-
.validate_contexts!(contexts, subjects:, view:) ⇒ Object
The shape is schema-validated first; these invariants relate sibling fields.
Class Method Details
.validate!(payload) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/petticoat/schema.rb', line 9 def self.validate!(payload) JSON::Validator.validate!(PATH, payload, validate_schema: true) validate_contexts!(payload.fetch('contexts'), subjects: payload.fetch('subjects'), view: payload.fetch('view')) expected = Digest::SHA256.hexdigest(Petticoat.canonical_json(payload.except('digest'))) raise Error, 'Content digest mismatch' unless payload.fetch('digest') == expected payload end |
.validate_contexts!(contexts, subjects:, view:) ⇒ Object
The shape is schema-validated first; these invariants relate sibling fields.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/petticoat/schema.rb', line 19 def self.validate_contexts!(contexts, subjects:, view:) contexts.each_value do |context| if view == 'resources' validate_resource_roles!(context, subjects) else context.fetch('roles').each_value do |states| raise Error, 'Unregistered action subject' unless (states.keys - subjects).empty? end end end contexts end |