Class: Compel::Validators::ArrayValidator
- Defined in:
- lib/compel/validators/array_validator.rb
Instance Attribute Summary collapse
-
#items_schema ⇒ Object
readonly
Returns the value of attribute items_schema.
Attributes inherited from Base
#errors, #input, #output, #schema
Instance Method Summary collapse
-
#initialize(input, schema) ⇒ ArrayValidator
constructor
A new instance of ArrayValidator.
- #serialize_errors ⇒ Object
- #validate ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(input, schema) ⇒ ArrayValidator
Returns a new instance of ArrayValidator.
8 9 10 11 12 13 14 |
# File 'lib/compel/validators/array_validator.rb', line 8 def initialize(input, schema) super @errors = Errors.new @output = [] @items_schema = schema.[:items][:value] if schema.[:items] end |
Instance Attribute Details
#items_schema ⇒ Object (readonly)
Returns the value of attribute items_schema.
6 7 8 |
# File 'lib/compel/validators/array_validator.rb', line 6 def items_schema @items_schema end |
Instance Method Details
#serialize_errors ⇒ Object
38 39 40 |
# File 'lib/compel/validators/array_validator.rb', line 38 def serialize_errors @errors.to_hash end |
#validate ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/compel/validators/array_validator.rb', line 16 def validate unless array_valid? return self end if items_schema.nil? @output = input return self end items_validator = \ ArrayItemsValidator.validate(input, items_schema) @output = items_validator.output unless items_validator.valid? @errors = items_validator.errors end self end |