Class: Acta::ArrayType

Inherits:
ActiveModel::Type::Value
  • Object
show all
Defined in:
lib/acta/array_type.rb

Instance Method Summary collapse

Constructor Details

#initialize(element_type) ⇒ ArrayType

Returns a new instance of ArrayType.



7
8
9
10
# File 'lib/acta/array_type.rb', line 7

def initialize(element_type)
  super()
  @element_type = element_type
end

Instance Method Details

#cast(value) ⇒ Object



12
13
14
15
16
# File 'lib/acta/array_type.rb', line 12

def cast(value)
  return nil if value.nil?

  Array(value).map { |el| @element_type.cast(el) }
end

#deserialize(value) ⇒ Object



24
25
26
27
28
# File 'lib/acta/array_type.rb', line 24

def deserialize(value)
  return nil if value.nil?

  value.map { |el| @element_type.deserialize(el) }
end

#serialize(value) ⇒ Object



18
19
20
21
22
# File 'lib/acta/array_type.rb', line 18

def serialize(value)
  return nil if value.nil?

  value.map { |el| @element_type.serialize(el) }
end