class Mutils::Serialization::BaseSerializer

BaseSerializer: inherit this class to get Serializer functionality

Attributes

options[RW]
scope[RW]

Public Class Methods

new(object, options = {}) click to toggle source
# File lib/mutils/serialization/base_serializer.rb, line 15
def initialize(object, options = {})
  options[:child] = false unless options[:child]
  self.scope = object
  self.options = options
end

Public Instance Methods

as_json(_options = {}) click to toggle source
# File lib/mutils/serialization/base_serializer.rb, line 21
def as_json(_options = {})
  if options[:child] || !self.class.include_root
    to_h
  else
    { class_name => to_h }
  end
end
to_h() click to toggle source
# File lib/mutils/serialization/base_serializer.rb, line 29
def to_h
  generate_hash
end
to_json(_options = {}) click to toggle source
# File lib/mutils/serialization/base_serializer.rb, line 33
def to_json(_options = {})
  JSON.generate(as_json, options)
end