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
-
#active_record ⇒ Object
readonly
Returns the value of attribute active_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:.
Instance Method Summary collapse
- #compute_class(name) ⇒ Object
-
#initialize(name, options, active_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, options, active_record) ⇒ MacroReflection
Returns a new instance of MacroReflection.
156 157 158 159 160 161 162 |
# File 'lib/duck_record/reflection.rb', line 156 def initialize(name, , active_record) @name = name = @active_record = active_record @klass = [:anonymous_class] @plural_name = name.to_s.pluralize end |
Instance Attribute Details
#active_record ⇒ Object (readonly)
Returns the value of attribute active_record.
152 153 154 |
# File 'lib/duck_record/reflection.rb', line 152 def active_record @active_record end |
#name ⇒ Object (readonly)
Returns the name of the macro.
composed_of :balance, class_name: 'Money' returns :balance has_many :clients returns :clients
144 145 146 |
# File 'lib/duck_record/reflection.rb', line 144 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 {}
150 151 152 |
# File 'lib/duck_record/reflection.rb', line 150 def end |
#plural_name ⇒ Object (readonly)
:nodoc:
154 155 156 |
# File 'lib/duck_record/reflection.rb', line 154 def plural_name @plural_name end |
Instance Method Details
#compute_class(name) ⇒ Object
172 173 174 |
# File 'lib/duck_record/reflection.rb', line 172 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
168 169 170 |
# File 'lib/duck_record/reflection.rb', line 168 def klass @klass ||= compute_class(class_name) end |