Class: ArrayOfObjectType

Inherits:
ActiveModel::Type::Value
  • Object
show all
Defined in:
app/types/array_of_object_type.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ ArrayOfObjectType

Returns a new instance of ArrayOfObjectType.



2
3
4
# File 'app/types/array_of_object_type.rb', line 2

def initialize(klass)
  @klass = klass
end

Instance Method Details

#cast(value) ⇒ Object



6
7
8
9
# File 'app/types/array_of_object_type.rb', line 6

def cast(value)
  return [] if value.blank?
  value.map { |v| @klass.new(v) }
end

#deserialize(value) ⇒ Object



15
16
17
# File 'app/types/array_of_object_type.rb', line 15

def deserialize(value)
  cast(value)
end

#serialize(value) ⇒ Object



11
12
13
# File 'app/types/array_of_object_type.rb', line 11

def serialize(value)
  value.map(&:attributes)
end