Class: YES::Constraints::Value
- Inherits:
-
NodeConstraint
- Object
- AbstractConstraint
- NodeConstraint
- YES::Constraints::Value
- Defined in:
- lib/yes/constraints/value.rb
Overview
Validate if a node’s value conforms to a constraint, where a value is either an sequence element or a mapping value.
//authors:
type: seq
value:
type: str
A valid code value could then have no more than three characters.
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 value 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
47 48 49 |
# File 'lib/yes/constraints/value.rb', line 47 def self.applicable?(spec) spec['value'] end |
.checklist(spec, tree, nodes) ⇒ Array<Constraint>
For value constraint, the work is all handled by the checklist method.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/yes/constraints/value.rb', line 20 def self.checklist(spec, tree, nodes) return [] unless applicable?(spec) vspec = spec['value'] list = [] nodes.each do |node| case node.kind when :seq YES.constraints.each do |c| list.concat(c.checklist(vspec, tree, node.children)) end when :map YES.constraints.each do |c| list.concat(c.checklist(vspec, tree, node.value.values)) end else # TODO: might value for scalars have a useful meaning? raise "value constraint does not apply to scalars" end end list end |
Instance Method Details
#validate(spec) ⇒ Boolean
no-op
55 56 |
# File 'lib/yes/constraints/value.rb', line 55 def validate(spec) end |