Module: PiResources::Serializer::ObjectSerializer

Extended by:
ActiveSupport::Concern
Includes:
Base
Included in:
MoneySerializer
Defined in:
lib/pi_resources/serializer/object_serializer.rb

Constant Summary

Constants included from Base

Base::TRANSFORMS_MAPPING

Instance Method Summary collapse

Methods included from Base

#as_json, #run_key_transform!, #to_h

Instance Method Details

#dataObject



40
41
42
43
44
45
46
# File 'lib/pi_resources/serializer/object_serializer.rb', line 40

def data
  if self.class.collection? @resource
    data_for_collection
  else
    data_for_one_record
  end
end

#initialize(resource, meta: nil, message: nil, context: nil, root: true) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/pi_resources/serializer/object_serializer.rb', line 23

def initialize(resource, meta: nil, message: nil, context: nil, root: true)
  @resource = resource
  @meta     = meta
  @message  = message
  @context  = context || {}
  @root     = root
end

#metaObject



48
49
50
51
52
# File 'lib/pi_resources/serializer/object_serializer.rb', line 48

def meta
  @meta&.deep_transform_keys do |k|
    run_key_transform!(k)
  end
end

#serializable_hash!Object



54
55
56
57
58
59
60
# File 'lib/pi_resources/serializer/object_serializer.rb', line 54

def serializable_hash!
  if root
    use_root
  else
    data
  end
end