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.
19 20 21 22 23 24 |
# File 'lib/light_serializer/serializer.rb', line 19 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.
6 7 8 |
# File 'lib/light_serializer/serializer.rb', line 6 def context @context end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
6 7 8 |
# File 'lib/light_serializer/serializer.rb', line 6 def @meta end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
6 7 8 |
# File 'lib/light_serializer/serializer.rb', line 6 def object @object end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
6 7 8 |
# File 'lib/light_serializer/serializer.rb', line 6 def root @root end |
Class Method Details
.attributes(*new_attributes) ⇒ Object
8 9 10 11 12 |
# File 'lib/light_serializer/serializer.rb', line 8 def self.attributes(*new_attributes) return (@attributes || []) if new_attributes.empty? @attributes = @attributes ? @attributes.concat(new_attributes) : new_attributes end |
.inherited(subclass) ⇒ Object
14 15 16 17 |
# File 'lib/light_serializer/serializer.rb', line 14 def self.inherited(subclass) subclass.attributes(*attributes) super(subclass) end |
Instance Method Details
#to_hash ⇒ Object
30 31 32 |
# File 'lib/light_serializer/serializer.rb', line 30 def to_hash ? hashed_object.merge!(meta: ) : hashed_object end |
#to_json ⇒ Object
26 27 28 |
# File 'lib/light_serializer/serializer.rb', line 26 def to_json Oj.dump(to_hash, mode: :compat) end |