class LightSerializer::Serializer

Attributes

context[R]
meta[R]
object[R]
root[R]

Public Class Methods

attributes(*new_attributes) click to toggle source
# 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) click to toggle source
Calls superclass method
# File lib/light_serializer/serializer.rb, line 14
def self.inherited(subclass)
  subclass.attributes(*attributes)
  super(subclass)
end
new(object, root: nil, context: nil, meta: nil) click to toggle source
# File lib/light_serializer/serializer.rb, line 19
def initialize(object, root: nil, context: nil, meta: nil)
  @object = object
  @root = root
  @context = context
  @meta = meta
end

Public Instance Methods

to_hash() click to toggle source
# File lib/light_serializer/serializer.rb, line 30
def to_hash
  meta ? hashed_object.merge!(meta: meta) : hashed_object
end
to_json() click to toggle source
# File lib/light_serializer/serializer.rb, line 26
def to_json
  Oj.dump(to_hash, mode: :compat)
end

Private Instance Methods

hashed_object() click to toggle source
# File lib/light_serializer/serializer.rb, line 36
def hashed_object
  HashedObject.get(object, self)
end