Class: YES::Constraints::Key
- Inherits:
-
NodeConstraint
- Object
- AbstractConstraint
- NodeConstraint
- YES::Constraints::Key
- Defined in:
- lib/yes/constraints/key.rb
Overview
Validate if a mapping node’s keys conforms to a constraint.
//authors:
type: map
key:
type: str
Instance Attribute Summary
Attributes inherited from NodeConstraint
Attributes inherited from AbstractConstraint
Class Method Summary collapse
- .applicable?(spec) ⇒ Boolean
-
.checklist(spec, tree, nodes) ⇒ Array<Constraint>
For key constraint, the work is all handled by the checklist method.
Instance Method Summary collapse
-
#validate(spec) ⇒ Boolean
no-op.
Methods inherited from NodeConstraint
Methods inherited from AbstractConstraint
#applicable?, inherited, #initialize, #match_delta, #recurse_valid?, #valid?
Constructor Details
This class inherits a constructor from YES::Constraints::NodeConstraint
Class Method Details
.applicable?(spec) ⇒ Boolean
40 41 42 |
# File 'lib/yes/constraints/key.rb', line 40 def self.applicable?(spec) spec['key'] end |
.checklist(spec, tree, nodes) ⇒ Array<Constraint>
For key constraint, the work is all handled by the checklist method.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/yes/constraints/key.rb', line 18 def self.checklist(spec, tree, nodes) return [] unless applicable?(spec) key_spec = spec['key'] list = [] nodes.each do |node| case node.kind when :map YES.constraints.each do |c| list.concat(c.checklist(key_spec, tree, node.value.keys)) end else raise "key constraint applies only to mappings" end end list end |
Instance Method Details
#validate(spec) ⇒ Boolean
no-op
48 49 |
# File 'lib/yes/constraints/key.rb', line 48 def validate(spec) end |