Class: ActiveAny::Associations::Preloader::Association
- Inherits:
-
Object
- Object
- ActiveAny::Associations::Preloader::Association
- Defined in:
- lib/active_any/associations/preloader/association.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#owners ⇒ Object
readonly
Returns the value of attribute owners.
-
#preload_scope ⇒ Object
readonly
Returns the value of attribute preload_scope.
-
#preloaded_records ⇒ Object
readonly
Returns the value of attribute preloaded_records.
-
#reflection ⇒ Object
readonly
Returns the value of attribute reflection.
Instance Method Summary collapse
-
#association_key_name ⇒ Object
The name of the key on the associated records.
-
#initialize(klass, owner_records, reflection, preload_scope) ⇒ Association
constructor
A new instance of Association.
- #options ⇒ Object
- #owner_key_name ⇒ Object
- #preload(_preloader) ⇒ Object
- #records_for(ids) ⇒ Object
- #run(preloader) ⇒ Object
- #scope ⇒ Object
Constructor Details
#initialize(klass, owner_records, reflection, preload_scope) ⇒ Association
Returns a new instance of Association.
11 12 13 14 15 16 17 |
# File 'lib/active_any/associations/preloader/association.rb', line 11 def initialize(klass, owner_records, reflection, preload_scope) @klass = klass @owners = owner_records @reflection = reflection @preload_scope = preload_scope @preloaded_records = [] end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
9 10 11 |
# File 'lib/active_any/associations/preloader/association.rb', line 9 def klass @klass end |
#owners ⇒ Object (readonly)
Returns the value of attribute owners.
9 10 11 |
# File 'lib/active_any/associations/preloader/association.rb', line 9 def owners @owners end |
#preload_scope ⇒ Object (readonly)
Returns the value of attribute preload_scope.
9 10 11 |
# File 'lib/active_any/associations/preloader/association.rb', line 9 def preload_scope @preload_scope end |
#preloaded_records ⇒ Object (readonly)
Returns the value of attribute preloaded_records.
9 10 11 |
# File 'lib/active_any/associations/preloader/association.rb', line 9 def preloaded_records @preloaded_records end |
#reflection ⇒ Object (readonly)
Returns the value of attribute reflection.
9 10 11 |
# File 'lib/active_any/associations/preloader/association.rb', line 9 def reflection @reflection end |
Instance Method Details
#association_key_name ⇒ Object
The name of the key on the associated records
36 37 38 |
# File 'lib/active_any/associations/preloader/association.rb', line 36 def association_key_name raise NotImplementedError end |
#options ⇒ Object
44 45 46 |
# File 'lib/active_any/associations/preloader/association.rb', line 44 def reflection. end |
#owner_key_name ⇒ Object
40 41 42 |
# File 'lib/active_any/associations/preloader/association.rb', line 40 def owner_key_name raise NotImplementedError end |
#preload(_preloader) ⇒ Object
23 24 25 |
# File 'lib/active_any/associations/preloader/association.rb', line 23 def preload(_preloader) raise NotImplementedError end |
#records_for(ids) ⇒ Object
31 32 33 |
# File 'lib/active_any/associations/preloader/association.rb', line 31 def records_for(ids) scope.where(association_key_name => ids) end |
#run(preloader) ⇒ Object
19 20 21 |
# File 'lib/active_any/associations/preloader/association.rb', line 19 def run(preloader) preload(preloader) end |
#scope ⇒ Object
27 28 29 |
# File 'lib/active_any/associations/preloader/association.rb', line 27 def scope @scope ||= build_scope end |