Class: J2119::Constraint

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConstraint

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