Class: DuckRecord::Reflection::MacroReflection
- Inherits:
-
AbstractReflection
- Object
- AbstractReflection
- DuckRecord::Reflection::MacroReflection
- Defined in:
- lib/duck_record/reflection.rb
Overview
Base class for AggregateReflection and AssociationReflection. Objects of AggregateReflection and AssociationReflection are returned by the Reflection::ClassMethods.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#duck_record ⇒ Object
readonly
Returns the value of attribute duck_record.
-
#name ⇒ Object
readonly
Returns the name of the macro.
-
#options ⇒ Object
readonly
Returns the hash of options used for the macro.
-
#plural_name ⇒ Object
readonly
:nodoc:.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
-
#==(other_aggregation) ⇒ Object
Returns
true
ifself
andother_aggregation
have the samename
attribute,active_record
attribute, andother_aggregation
has an options hash assigned to it. - #compute_class(name) ⇒ Object
-
#initialize(name, scope, options, duck_record) ⇒ MacroReflection
constructor
A new instance of MacroReflection.
-
#klass ⇒ Object
Returns the class for the macro.
Methods inherited from AbstractReflection
#alias_candidate, #build_association, #check_validity!, #class_name
Constructor Details
#initialize(name, scope, options, duck_record) ⇒ MacroReflection
Returns a new instance of MacroReflection.
168 169 170 171 172 173 174 175 |
# File 'lib/duck_record/reflection.rb', line 168 def initialize(name, scope, , duck_record) @name = name @scope = scope @options = @duck_record = duck_record @klass = [:anonymous_class] @plural_name = name.to_s.pluralize end |
Instance Attribute Details
#duck_record ⇒ Object (readonly)
Returns the value of attribute duck_record.
164 165 166 |
# File 'lib/duck_record/reflection.rb', line 164 def duck_record @duck_record end |
#name ⇒ Object (readonly)
Returns the name of the macro.
composed_of :balance, class_name: 'Money'
returns :balance
has_many :clients
returns :clients
154 155 156 |
# File 'lib/duck_record/reflection.rb', line 154 def name @name end |
#options ⇒ Object (readonly)
Returns the hash of options used for the macro.
composed_of :balance, class_name: 'Money'
returns { class_name: "Money" }
has_many :clients
returns {}
162 163 164 |
# File 'lib/duck_record/reflection.rb', line 162 def @options end |
#plural_name ⇒ Object (readonly)
:nodoc:
166 167 168 |
# File 'lib/duck_record/reflection.rb', line 166 def plural_name @plural_name end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
156 157 158 |
# File 'lib/duck_record/reflection.rb', line 156 def scope @scope end |
Instance Method Details
#==(other_aggregation) ⇒ Object
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.
191 192 193 194 195 196 197 |
# File 'lib/duck_record/reflection.rb', line 191 def ==(other_aggregation) super || other_aggregation.kind_of?(self.class) && name == other_aggregation.name && !other_aggregation..nil? && active_record == other_aggregation.active_record end |
#compute_class(name) ⇒ Object
185 186 187 |
# File 'lib/duck_record/reflection.rb', line 185 def compute_class(name) name.constantize end |
#klass ⇒ Object
Returns the class for the macro.
composed_of :balance, class_name: 'Money'
returns the Money class has_many :clients
returns the Client class
181 182 183 |
# File 'lib/duck_record/reflection.rb', line 181 def klass @klass ||= compute_class(class_name) end |