class Cyrax::Serializer

Public Class Methods

assigned(name, &block) click to toggle source
# File lib/cyrax/serializer.rb, line 39
def assigned(name, &block)
  scope.assigned(name, &block)
end
attribute(attribute, options = {}, &block) click to toggle source
# File lib/cyrax/serializer.rb, line 57
def attribute(attribute, options = {}, &block)
  scope.attribute(attribute, options, &block)
end
attributes(*attrs) click to toggle source
# File lib/cyrax/serializer.rb, line 53
def attributes(*attrs)
  scope.attributes(*attrs)
end
default_attributes() click to toggle source
# File lib/cyrax/serializer.rb, line 49
def default_attributes
  scope.default_attributes
end
has_many(name, &block)
Alias for: relation
has_one(name, &block)
Alias for: relation
namespace(name, &block) click to toggle source
# File lib/cyrax/serializer.rb, line 35
def namespace(name, &block)
  scope.namespace(name, &block)
end
relation(name, &block) click to toggle source
# File lib/cyrax/serializer.rb, line 43
def relation(name, &block)
  scope.relation(name, &block)
end
Also aliased as: has_many, has_one
scope() click to toggle source
# File lib/cyrax/serializer.rb, line 23
def scope
  @scope ||= Cyrax::Serializers::Scope.new()
end
total_count(&block) click to toggle source
# File lib/cyrax/serializer.rb, line 27
def total_count(&block)
  @total_count_block = block
end
total_count_block() click to toggle source
# File lib/cyrax/serializer.rb, line 31
def total_count_block
  @total_count_block
end

Public Instance Methods

serialize() click to toggle source
# File lib/cyrax/serializer.rb, line 2
def serialize
  options[:serializer] = self
  
  if block = self.class.total_count_block
    serialize_wrapped(options, &block)
  else
    serialize_simple(options)
  end
end
serialize_simple(options = {}) click to toggle source
# File lib/cyrax/serializer.rb, line 12
def serialize_simple(options = {})
  self.class.scope.serialize(resource, options)
end
serialize_wrapped(options = {}, &counter_block) click to toggle source
# File lib/cyrax/serializer.rb, line 16
def serialize_wrapped(options = {}, &counter_block)
  total_count = self.instance_eval(&counter_block)
  data = self.class.scope.serialize(resource, options)
  {total_count: total_count, data: data}
end