class Cereals::Serializer
Public Class Methods
new(object)
click to toggle source
# File lib/cereals/serializer.rb, line 5 def initialize(object) @object = object end
Public Instance Methods
as_json(options = {})
click to toggle source
override ActiveSupport's as_json
# File lib/cereals/serializer.rb, line 19 def as_json(options = {}) options[:root] = true unless options.key?(:root) if options[:root] { root_name => to_hash } else to_hash end end
to_json(options = {})
click to toggle source
super is defined in ActiveSupport::ToJsonWithActiveSupportEncoder
Calls superclass method
# File lib/cereals/serializer.rb, line 13 def to_json(options = {}) options[:root] = true unless options.key?(:root) super(options) end
Private Instance Methods
root_name()
click to toggle source
# File lib/cereals/serializer.rb, line 30 def root_name @object.class.name.underscore end