Class: LightSerializer::Serializer
- Inherits:
-
Object
- Object
- LightSerializer::Serializer
- Defined in:
- lib/light_serializer/serializer.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(object, root: nil, context: nil, meta: nil) ⇒ Serializer
constructor
A new instance of Serializer.
- #to_hash ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(object, root: nil, context: nil, meta: nil) ⇒ Serializer
Returns a new instance of Serializer.
18 19 20 21 22 23 |
# File 'lib/light_serializer/serializer.rb', line 18 def initialize(object, root: nil, context: nil, meta: nil) @object = object @root = root @context = context @meta = end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/light_serializer/serializer.rb', line 5 def context @context end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
5 6 7 |
# File 'lib/light_serializer/serializer.rb', line 5 def @meta end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/light_serializer/serializer.rb', line 5 def object @object end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
5 6 7 |
# File 'lib/light_serializer/serializer.rb', line 5 def root @root end |
Class Method Details
.attributes(*new_attributes) ⇒ Object
7 8 9 10 11 |
# File 'lib/light_serializer/serializer.rb', line 7 def self.attributes(*new_attributes) return @attributes if new_attributes.empty? @attributes = @attributes ? @attributes.concat(new_attributes) : new_attributes end |
.inherited(subclass) ⇒ Object
13 14 15 16 |
# File 'lib/light_serializer/serializer.rb', line 13 def self.inherited(subclass) subclass.attributes(*attributes) super(subclass) end |
Instance Method Details
#to_hash ⇒ Object
29 30 31 |
# File 'lib/light_serializer/serializer.rb', line 29 def to_hash ? hashed_object.merge!(meta: ) : hashed_object end |
#to_json ⇒ Object
25 26 27 |
# File 'lib/light_serializer/serializer.rb', line 25 def to_json Oj.dump(to_hash, mode: :compat) end |