class ActiveRecord::Aggregations::AggregationReflection

Attributes

attribute[R]
constructor[R]
klass_name[R]
mapped_attributes[R]

Public Class Methods

new(owner_class, macro, name, options = {}) click to toggle source
# File lib/reactive_record/active_record/aggregations.rb, line 28
def initialize(owner_class, macro, name, options = {})
  owner_class.reflect_on_all_aggregations << self
  @owner_class = owner_class
  @constructor = options[:constructor] || :new
  @klass_name =  options[:class_name] || name.camelize
  @attribute =   name
  if options[:mapping].respond_to? :collect
    @mapped_attributes = options[:mapping].collect &:last
  else
    ReactiveRecord::Base.log("improper aggregate definition #{@owner_class}, :#{name}, class_name: #{@klass_name} - missing mapping", :error)
    @mapped_attributes = []
  end
end

Public Instance Methods

construct(args) click to toggle source
# File lib/reactive_record/active_record/aggregations.rb, line 24
def construct(args)

end
deserialize(array) click to toggle source
# File lib/reactive_record/active_record/aggregations.rb, line 54
def deserialize(array)
  if array.nil?
    array # return dummy value if that is what we got
  elsif @constructor.respond_to?(:call)
    @constructor.call(*array)
  else
    klass.send(@constructor, *array)
  end
end
klass() click to toggle source
# File lib/reactive_record/active_record/aggregations.rb, line 42
def klass
  @klass ||= Object.const_get(@klass_name)
end
serialize(object) click to toggle source
# File lib/reactive_record/active_record/aggregations.rb, line 46
def serialize(object)
  if object.nil?
    object # return dummy value if that is what we got
  else
    @mapped_attributes.collect { |attr| object.send(attr) }
  end
end