Class: YES::Constraints::Required
- Inherits:
-
TreeConstraint
- Object
- AbstractConstraint
- TreeConstraint
- YES::Constraints::Required
- Defined in:
- lib/yes/constraints/required.rb
Overview
TODO: For the moment this is the same as Inclusive.
It was originall inteded to work like {RequiresValidation}
but it rpoved hard to work out the validation procedure
when matching to the subfield. If we can fix it maybe we will
keep, but for now THIS IS NOT USED.
Instance Attribute Summary
Attributes inherited from AbstractConstraint
Class Method Summary collapse
-
.applicable?(spec) ⇒ Boolean
Only applicable if ‘required` field appears in spec.
- .checklist(spec, tree, nodes) ⇒ Array<Constraint>
Instance Method Summary collapse
-
#validate(spec) ⇒ Boolean
Validates whether a matching node must be present within it’s parent.
Methods inherited from AbstractConstraint
#applicable?, inherited, #initialize, #match_delta, #recurse_valid?, #valid?
Constructor Details
This class inherits a constructor from YES::Constraints::AbstractConstraint
Class Method Details
.applicable?(spec) ⇒ Boolean
Only applicable if ‘required` field appears in spec.
22 23 24 |
# File 'lib/yes/constraints/required.rb', line 22 def self.applicable?(spec) spec['required'] end |
.checklist(spec, tree, nodes) ⇒ Array<Constraint>
16 17 18 19 |
# File 'lib/yes/constraints/required.rb', line 16 def self.checklist(spec, tree, nodes) return [] unless applicable?(spec) [new(spec, tree, nodes)] end |
Instance Method Details
#validate(spec) ⇒ Boolean
Validates whether a matching node must be present within it’s parent.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/yes/constraints/required.rb', line 29 def validate(spec) required = spec['required'] case required when true, false nodes.size > 0 else in_nodes = tree.select(required) nodes.size == 0 or in_nodes.size > 0 end end |