Class: OccamsRecord::EagerLoaders::Base
- Inherits:
-
Object
- Object
- OccamsRecord::EagerLoaders::Base
- Defined in:
- lib/occams-record/eager_loaders/base.rb
Overview
Base class for eagoer loading an association.
Instance Attribute Summary collapse
-
#eval_block ⇒ Proc
readonly
Optional Proc for eager loading things on this association.
-
#name ⇒ String
readonly
Association name.
-
#use ⇒ Array<Module>
readonly
Optional Module to include in the result class (single or array).
Instance Method Summary collapse
-
#initialize(ref, scope = nil, use: nil, as: nil) { ... } ⇒ Base
constructor
ActiveRecord::Relation on which you may call all the normal query hethods (select, where, etc) as well as any scopes you’ve defined on the model.
-
#merge!(assoc_rows, rows) ⇒ Object
Merges the associated rows into the parent rows.
-
#query(rows) ⇒ Object
Yield one or more ActiveRecord::Relation objects to a given block.
Constructor Details
#initialize(ref, scope = nil, use: nil, as: nil) { ... } ⇒ Base
ActiveRecord::Relation on which you may call all the normal query hethods (select, where, etc) as well as any scopes you’ve defined on the model.
22 23 24 25 26 |
# File 'lib/occams-record/eager_loaders/base.rb', line 22 def initialize(ref, scope = nil, use: nil, as: nil, &eval_block) @ref, @scope, @use, @as, @eval_block = ref, scope, use, as, eval_block @model = ref.klass @name = (as || ref.name).to_s end |
Instance Attribute Details
#eval_block ⇒ Proc (readonly)
Returns optional Proc for eager loading things on this association.
12 13 14 |
# File 'lib/occams-record/eager_loaders/base.rb', line 12 def eval_block @eval_block end |
#name ⇒ String (readonly)
Returns association name.
8 9 10 |
# File 'lib/occams-record/eager_loaders/base.rb', line 8 def name @name end |
#use ⇒ Array<Module> (readonly)
Returns optional Module to include in the result class (single or array).
10 11 12 |
# File 'lib/occams-record/eager_loaders/base.rb', line 10 def use @use end |
Instance Method Details
#merge!(assoc_rows, rows) ⇒ Object
Merges the associated rows into the parent rows.
43 44 45 |
# File 'lib/occams-record/eager_loaders/base.rb', line 43 def merge!(assoc_rows, rows) raise 'Not Implemented' end |
#query(rows) ⇒ Object
Yield one or more ActiveRecord::Relation objects to a given block.
33 34 35 |
# File 'lib/occams-record/eager_loaders/base.rb', line 33 def query(rows) raise 'Not Implemented' end |