class DuckRecord::Reflection::MacroReflection
Base
class for AggregateReflection and AssociationReflection
. Objects of AggregateReflection and AssociationReflection
are returned by the Reflection::ClassMethods
.
Attributes
duck_record[R]
name[R]
Returns the name of the macro.
composed_of :balance, class_name: 'Money'
returns :balance
has_many :clients
returns :clients
options[R]
Returns the hash of options used for the macro.
composed_of :balance, class_name: 'Money'
returns { class_name: "Money" }
has_many :clients
returns {}
scope[R]
Public Class Methods
new(name, scope, options, duck_record)
click to toggle source
# File lib/duck_record/reflection.rb, line 168 def initialize(name, scope, options, duck_record) @name = name @scope = scope @options = options @duck_record = duck_record @klass = options[:anonymous_class] @plural_name = name.to_s.pluralize end
Public Instance Methods
==(other_aggregation)
click to toggle source
Returns true
if self
and other_aggregation
have the same name
attribute, active_record
attribute, and other_aggregation
has an options hash assigned to it.
Calls superclass method
# File lib/duck_record/reflection.rb, line 191 def ==(other_aggregation) super || other_aggregation.kind_of?(self.class) && name == other_aggregation.name && !other_aggregation.options.nil? && active_record == other_aggregation.active_record end
compute_class(name)
click to toggle source
# File lib/duck_record/reflection.rb, line 185 def compute_class(name) name.constantize end
klass()
click to toggle source
Returns the class for the macro.
composed_of :balance, class_name: 'Money'
returns the Money class has_many :clients
returns the Client class
# File lib/duck_record/reflection.rb, line 181 def klass @klass ||= compute_class(class_name) end
Private Instance Methods
derive_class_name()
click to toggle source
# File lib/duck_record/reflection.rb, line 201 def derive_class_name name.to_s.camelize end