Class: J2119::NonEmptyConstraint

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

Overview

Verify that array field is not empty

Instance Method Summary collapse

Methods inherited from Constraint

#add_condition, #applies

Constructor Details

#initialize(name) ⇒ NonEmptyConstraint

Returns a new instance of NonEmptyConstraint.



58
59
60
61
# File 'lib/j2119/constraints.rb', line 58

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

Instance Method Details

#check(node, path, problems) ⇒ Object



68
69
70
71
72
73
# File 'lib/j2119/constraints.rb', line 68

def check(node, path, problems)
  if node[@name] && node[@name].is_a?(Array) && (node[@name].size == 0)
    problems <<
      "#{path}.#{@name} is empty, non-empty required"
  end
end

#to_sObject



63
64
65
66
# File 'lib/j2119/constraints.rb', line 63

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