Class: TypedModel::SeqOf

Inherits:
Object
  • Object
show all
Defined in:
lib/typed_model/seq_of.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ SeqOf

Returns a new instance of SeqOf.



5
6
7
# File 'lib/typed_model/seq_of.rb', line 5

def initialize(spec)
  @spec = spec
end

Instance Attribute Details

#specObject (readonly)

Returns the value of attribute spec.



3
4
5
# File 'lib/typed_model/seq_of.rb', line 3

def spec
  @spec
end

Instance Method Details

#to_data(values) ⇒ Object



13
14
15
# File 'lib/typed_model/seq_of.rb', line 13

def to_data(values)
  values.map { |v| spec.to_data(v) }
end

#typecast_value(values) ⇒ Object



9
10
11
# File 'lib/typed_model/seq_of.rb', line 9

def typecast_value(values)
  values.map { |v| spec.typecast_value(v) }
end

#validate(value, errors, key_prefix) ⇒ Object



17
18
19
20
21
# File 'lib/typed_model/seq_of.rb', line 17

def validate(value, errors, key_prefix)
  value&.each_with_index do |v, index|
    spec.validate(v, errors, "#{key_prefix}/#{index}")
  end
end