Class: RSchema::Schemas::FixedLengthArray
- Inherits:
-
Object
- Object
- RSchema::Schemas::FixedLengthArray
- Defined in:
- lib/rschema/schemas/fixed_length_array.rb
Overview
A schema that represents an array of fixed length
Each element in the fixed-length array has its own subschema
Instance Attribute Summary collapse
-
#subschemas ⇒ Object
readonly
Returns the value of attribute subschemas.
Instance Method Summary collapse
- #call(value, options) ⇒ Object
-
#initialize(subschemas) ⇒ FixedLengthArray
constructor
A new instance of FixedLengthArray.
- #with_wrapped_subschemas(wrapper) ⇒ Object
Constructor Details
#initialize(subschemas) ⇒ FixedLengthArray
Returns a new instance of FixedLengthArray.
19 20 21 |
# File 'lib/rschema/schemas/fixed_length_array.rb', line 19 def initialize(subschemas) @subschemas = subschemas end |
Instance Attribute Details
#subschemas ⇒ Object (readonly)
Returns the value of attribute subschemas.
17 18 19 |
# File 'lib/rschema/schemas/fixed_length_array.rb', line 17 def subschemas @subschemas end |
Instance Method Details
#call(value, options) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rschema/schemas/fixed_length_array.rb', line 23 def call(value, ) return type_failure(value) unless value.is_a?(Array) return size_failure(value) unless value.size == @subschemas.size validated_array, error = apply_subschemas(value, ) if error.empty? Result.success(validated_array) else Result.failure(error) end end |
#with_wrapped_subschemas(wrapper) ⇒ Object
35 36 37 38 |
# File 'lib/rschema/schemas/fixed_length_array.rb', line 35 def with_wrapped_subschemas(wrapper) wrapped_subschemas = subschemas.map { |ss| wrapper.wrap(ss) } self.class.new(wrapped_subschemas) end |