class SerializableRails::Serializer
Attributes
_object[R]
Public Class Methods
new(object)
click to toggle source
# File lib/serializable_rails/serializer.rb, line 7 def initialize(object) @_object = object end
Private Class Methods
attributes(*attrs)
click to toggle source
# File lib/serializable_rails/serializer.rb, line 28 def attributes(*attrs) attrs.each { |attr| defined_attributes.push(attr.to_s) } end
Also aliased as: attribute
defined_attributes()
click to toggle source
# File lib/serializable_rails/serializer.rb, line 33 def defined_attributes @defined_attributes ||= [] end
Public Instance Methods
as_json(*args)
click to toggle source
# File lib/serializable_rails/serializer.rb, line 11 def as_json(*args) self.class.defined_attributes.each_with_object({}) { |attr, h| catch(:skip) { h[attr] = value_for(attr, args).as_json } } end
Private Instance Methods
value_for(attr, args)
click to toggle source
# File lib/serializable_rails/serializer.rb, line 19 def value_for(attr, args) if respond_to?(attr) send(attr) else _object.send(attr) end end