Class: Mirah::Serializers::NestedObjectSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/mirah/serializers.rb

Overview

Serialize subobjects using their standard serializer

Instance Method Summary collapse

Constructor Details

#initialize(subclass) ⇒ NestedObjectSerializer

Returns a new instance of NestedObjectSerializer.


59
60
61
# File 'lib/mirah/serializers.rb', line 59

def initialize(subclass)
  @subclass = subclass
end

Instance Method Details

#deserialize(value) ⇒ Object


71
72
73
74
75
76
77
# File 'lib/mirah/serializers.rb', line 71

def deserialize(value)
  if value.is_a? Array
    value.map { |item| @subclass.from_graphql_hash(item) }
  else
    @subclass.from_graphql_hash(value)
  end
end

#serialize(value) ⇒ Object


63
64
65
66
67
68
69
# File 'lib/mirah/serializers.rb', line 63

def serialize(value)
  if value.is_a? Array
    value.map(&:to_graphql_hash)
  else
    value.to_graphql_hash
  end
end