Class: J2119::DoesNotHaveFieldConstraint

Inherits:
Constraint
  • Object
show all
Defined in:
lib/j2119/constraints.rb

Overview

Verify node does not have the named field

Instance Method Summary collapse

Methods inherited from Constraint

#add_condition, #applies

Constructor Details

#initialize(name) ⇒ DoesNotHaveFieldConstraint

Returns a new instance of DoesNotHaveFieldConstraint.



109
110
111
112
# File 'lib/j2119/constraints.rb', line 109

def initialize(name)
  super()
  @name = name
end

Instance Method Details

#check(node, path, problems) ⇒ Object



119
120
121
122
123
124
# File 'lib/j2119/constraints.rb', line 119

def check(node, path, problems)
  if node[@name]
    problems <<
      "#{path} has forbidden field \"#{@name}\""
  end
end

#to_sObject



114
115
116
117
# File 'lib/j2119/constraints.rb', line 114

def to_s
  conds = (@conditions.empty?) ? '' : " #{@conditions.size} conditions"
  "<Field #{@name} should be absent#{conds}>"
end