Class: Schemacop::ArrayValidator
- Inherits:
-
NodeSupportingType
- Object
- Node
- NodeWithBlock
- NodeSupportingType
- Schemacop::ArrayValidator
- Defined in:
- lib/schemacop/validator/array_validator.rb
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize(*args) ⇒ ArrayValidator
constructor
A new instance of ArrayValidator.
- #validate(data, collector) ⇒ Object
Methods inherited from NodeSupportingType
Methods inherited from NodeWithBlock
Methods inherited from Node
build, class_matches?, clear_klasses, clear_symbols, #exec_block, klass, option, #option, #option?, register, #resolve_type_klass, symbol, symbol_matches?, #type_filter_matches?, #type_label, type_matches?, #type_matches?
Constructor Details
#initialize(*args) ⇒ ArrayValidator
Returns a new instance of ArrayValidator
9 10 11 12 |
# File 'lib/schemacop/validator/array_validator.rb', line 9 def initialize(*args) super type(:nil) if option(:nil) end |
Instance Method Details
#validate(data, collector) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/schemacop/validator/array_validator.rb', line 14 def validate(data, collector) validate_custom_check(data, collector) if option?(:min) && data.size < option(:min) collector.error "Array must have more (>=) than #{option(:min)} elements." end if option?(:max) && data.size > option(:max) collector.error "Array must have less (<=) than #{option(:max)} elements." end data.each_with_index do |entry, index| collector.path("[#{index}]", index, :array) do validate_types(entry, collector) end end end |