Class: J2119::Constraint
- Inherits:
-
Object
- Object
- J2119::Constraint
- Defined in:
- lib/j2119/constraints.rb
Overview
These all respond_to check(node, path, problem)
- node is the JSON node being checked
- path is the current path, for reporting practices
- problems is a list of problem reports
TODO: Add a “role” argument to enrich error reporting
Direct Known Subclasses
DoesNotHaveFieldConstraint, FieldTypeConstraint, FieldValueConstraint, HasFieldConstraint, NonEmptyConstraint, OnlyOneOfConstraint
Instance Method Summary collapse
- #add_condition(condition) ⇒ Object
- #applies(node, role) ⇒ Object
-
#initialize ⇒ Constraint
constructor
A new instance of Constraint.
Constructor Details
#initialize ⇒ Constraint
Returns a new instance of Constraint.
25 26 27 |
# File 'lib/j2119/constraints.rb', line 25 def initialize @conditions = [] end |
Instance Method Details
#add_condition(condition) ⇒ Object
29 30 31 |
# File 'lib/j2119/constraints.rb', line 29 def add_condition(condition) @conditions << condition end |
#applies(node, role) ⇒ Object
33 34 35 36 |
# File 'lib/j2119/constraints.rb', line 33 def applies(node, role) return @conditions.empty? || @conditions.map{|c| c.constraint_applies(node, role)}.any? end |