Class: J2119::NonEmptyConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- J2119::NonEmptyConstraint
- Defined in:
- lib/j2119/constraints.rb
Overview
Verify that array field is not empty
Instance Method Summary collapse
- #check(node, path, problems) ⇒ Object
-
#initialize(name) ⇒ NonEmptyConstraint
constructor
A new instance of NonEmptyConstraint.
- #to_s ⇒ Object
Methods inherited from Constraint
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_s ⇒ Object
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 |