Class: LightSerializer::HashedObject

Inherits:
Object
  • Object
show all
Includes:
LightSerializer::Helpers::WithCustomRoot
Defined in:
lib/light_serializer/hashed_object.rb

Constant Summary collapse

UnknownAttribute =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LightSerializer::Helpers::WithCustomRoot

#with_custom_root

Constructor Details

#initialize(raw_object, serializer) ⇒ HashedObject

Returns a new instance of HashedObject.



15
16
17
18
# File 'lib/light_serializer/hashed_object.rb', line 15

def initialize(raw_object, serializer)
  @raw_object = raw_object
  @serializer = serializer
end

Instance Attribute Details

#raw_objectObject (readonly)

Returns the value of attribute raw_object.



9
10
11
# File 'lib/light_serializer/hashed_object.rb', line 9

def raw_object
  @raw_object
end

#serializerObject (readonly)

Returns the value of attribute serializer.



9
10
11
# File 'lib/light_serializer/hashed_object.rb', line 9

def serializer
  @serializer
end

Class Method Details

.get(*args) ⇒ Object



11
12
13
# File 'lib/light_serializer/hashed_object.rb', line 11

def self.get(*args)
  new(*args).get
end

Instance Method Details

#getObject



20
21
22
# File 'lib/light_serializer/hashed_object.rb', line 20

def get
  with_custom_root(serializer.root) { transform_to_hash(raw_object) }
end