class J2119::HasFieldConstraint

Verify node has the named field, or one of the named fields

Public Class Methods

new(name) click to toggle source
Calls superclass method J2119::Constraint::new
# File lib/j2119/constraints.rb, line 79
def initialize(name)
  super()
  if name.is_a?(String)
    @names = [ name ]
  else
    @names = name
  end
end

Public Instance Methods

check(node, path, problems) click to toggle source
# File lib/j2119/constraints.rb, line 93
def check(node, path, problems)
  if (node.keys & @names).empty?
    if @names.size == 1
      problems <<
        "#{path} does not have required field \"#{@names[0]}\""
    else
      problems <<
        "#{path} does not have required field from #{@names}"
    end
  end
end
to_s() click to toggle source
# File lib/j2119/constraints.rb, line 88
def to_s
  conds = (@conditions.empty?) ? '' : " #{@conditions.size} conditions"
  "<Field #{@names} should be present#{conds}>"
end