Class: ActiveRecord::Aggregations::AggregationReflection
- Defined in:
- lib/reactive_record/active_record/aggregations.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#constructor ⇒ Object
readonly
Returns the value of attribute constructor.
-
#klass_name ⇒ Object
readonly
Returns the value of attribute klass_name.
-
#mapped_attributes ⇒ Object
readonly
Returns the value of attribute mapped_attributes.
Instance Method Summary collapse
- #construct(args) ⇒ Object
- #deserialize(array) ⇒ Object
-
#initialize(owner_class, macro, name, options = {}) ⇒ AggregationReflection
constructor
A new instance of AggregationReflection.
- #klass ⇒ Object
- #serialize(object) ⇒ Object
Constructor Details
#initialize(owner_class, macro, name, options = {}) ⇒ AggregationReflection
Returns a new instance of AggregationReflection.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/reactive_record/active_record/aggregations.rb', line 28 def initialize(owner_class, macro, name, = {}) owner_class.reflect_on_all_aggregations << self @owner_class = owner_class @constructor = [:constructor] || :new @klass_name = [:class_name] || name.camelize @attribute = name if [:mapping].respond_to? :collect @mapped_attributes = [:mapping].collect &:last else ReactiveRecord::Base.log("improper aggregate definition #{@owner_class}, :#{name}, class_name: #{@klass_name} - missing mapping", :error) @mapped_attributes = [] end end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
20 21 22 |
# File 'lib/reactive_record/active_record/aggregations.rb', line 20 def attribute @attribute end |
#constructor ⇒ Object (readonly)
Returns the value of attribute constructor.
22 23 24 |
# File 'lib/reactive_record/active_record/aggregations.rb', line 22 def constructor @constructor end |
#klass_name ⇒ Object (readonly)
Returns the value of attribute klass_name.
19 20 21 |
# File 'lib/reactive_record/active_record/aggregations.rb', line 19 def klass_name @klass_name end |
#mapped_attributes ⇒ Object (readonly)
Returns the value of attribute mapped_attributes.
21 22 23 |
# File 'lib/reactive_record/active_record/aggregations.rb', line 21 def mapped_attributes @mapped_attributes end |
Instance Method Details
#construct(args) ⇒ Object
24 25 26 |
# File 'lib/reactive_record/active_record/aggregations.rb', line 24 def construct(args) end |
#deserialize(array) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# 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 ⇒ Object
42 43 44 |
# File 'lib/reactive_record/active_record/aggregations.rb', line 42 def klass @klass ||= Object.const_get(@klass_name) end |
#serialize(object) ⇒ Object
46 47 48 49 50 51 52 |
# 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 |