Module: Serega::SeregaObjectSerializer::InstanceMethods

Included in:
Serega::SeregaObjectSerializer
Defined in:
lib/serega/object_serializer.rb

Overview

SeregaObjectSerializer instance methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



13
14
15
# File 'lib/serega/object_serializer.rb', line 13

def context
  @context
end

#manyObject (readonly)

Returns the value of attribute many.



13
14
15
# File 'lib/serega/object_serializer.rb', line 13

def many
  @many
end

#optsObject (readonly)

Returns the value of attribute opts.



13
14
15
# File 'lib/serega/object_serializer.rb', line 13

def opts
  @opts
end

#pointsObject (readonly)

Returns the value of attribute points.



13
14
15
# File 'lib/serega/object_serializer.rb', line 13

def points
  @points
end

Instance Method Details

#initialize(context:, points:, many: nil, **opts) ⇒ SeregaObjectSerializer

Returns New SeregaObjectSerializer.

Parameters:

  • context (Hash)

    Serialization context

  • many (TrueClass|FalseClass) (defaults to: nil)

    is object is enumerable

  • points (Array<MapPoint>)

    Serialization points (attributes)

Returns:



20
21
22
23
24
25
# File 'lib/serega/object_serializer.rb', line 20

def initialize(context:, points:, many: nil, **opts)
  @context = context
  @points = points
  @many = many
  @opts = opts
end

#serialize(object) ⇒ Hash+

Serializes object(s)

Parameters:

  • object (Object)

    Serialized object

Returns:

  • (Hash, Array<Hash>)

    Serialized object(s)



32
33
34
35
36
# File 'lib/serega/object_serializer.rb', line 32

def serialize(object)
  return if object.nil?

  array?(object, many) ? serialize_array(object) : serialize_object(object)
end