Class: RSchema::Schemas::VariableLengthArray
- Inherits:
-
Object
- Object
- RSchema::Schemas::VariableLengthArray
- Defined in:
- lib/rschema/schemas/variable_length_array.rb
Overview
A schema that matches variable-length arrays, where all elements conform to a single subschema
Instance Attribute Summary collapse
-
#element_schema ⇒ Object
Returns the value of attribute element_schema.
Instance Method Summary collapse
- #call(value, options) ⇒ Object
-
#initialize(element_schema) ⇒ VariableLengthArray
constructor
A new instance of VariableLengthArray.
- #with_wrapped_subschemas(wrapper) ⇒ Object
Constructor Details
#initialize(element_schema) ⇒ VariableLengthArray
Returns a new instance of VariableLengthArray.
17 18 19 |
# File 'lib/rschema/schemas/variable_length_array.rb', line 17 def initialize(element_schema) @element_schema = element_schema end |
Instance Attribute Details
#element_schema ⇒ Object
Returns the value of attribute element_schema.
15 16 17 |
# File 'lib/rschema/schemas/variable_length_array.rb', line 15 def element_schema @element_schema end |
Instance Method Details
#call(value, options) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rschema/schemas/variable_length_array.rb', line 21 def call(value, ) return type_failure(value) unless value.is_a?(Array) validated_values, errors = validate_elements(value, ) if errors.empty? Result.success(validated_values) else Result.failure(errors) end end |
#with_wrapped_subschemas(wrapper) ⇒ Object
32 33 34 |
# File 'lib/rschema/schemas/variable_length_array.rb', line 32 def with_wrapped_subschemas(wrapper) self.class.new(wrapper.wrap(element_schema)) end |