class SimpleObjectSerialization::Entity

Attributes

object[R]
options[R]

Public Class Methods

attributes() click to toggle source
# File lib/simple_object_serialization/entity.rb, line 28
def self.attributes
  @attributes ||= Attributes.new
end
call(*params, **options, &block) click to toggle source
# File lib/simple_object_serialization/entity.rb, line 12
def self.call(*params, **options, &block)
  new(*params, **options).call(&block)
end
define_attribute(name, options = {}, &block) click to toggle source
# File lib/simple_object_serialization/entity.rb, line 22
def self.define_attribute(name, options = {}, &block)
  attribute = Attribute.new(name, options, block)

  attributes.push(attribute)
end
new(object, options = {}) click to toggle source
# File lib/simple_object_serialization/entity.rb, line 7
def initialize(object, options = {})
  @object = object
  @options = options
end
object_alias(name) click to toggle source
# File lib/simple_object_serialization/entity.rb, line 16
def self.object_alias(name)
  define_method(name) do
    object
  end
end
serialize(object, options = {}) click to toggle source
# File lib/simple_object_serialization/entity.rb, line 38
def self.serialize(object, options = {})
  hash = ObjectSerializer.call(self, object, options)

  JSON.generate(hash)
end
serialize_collection(collection, options = {}) click to toggle source
# File lib/simple_object_serialization/entity.rb, line 32
def self.serialize_collection(collection, options = {})
  hash = CollectionSerializer.call(self, collection, options)

  JSON.generate(hash)
end

Public Instance Methods

call() click to toggle source
# File lib/simple_object_serialization/entity.rb, line 44
def call
  self.class.attributes.hash_for(self)
end