Class: Dase::Preloader
- Inherits:
-
ActiveRecord::Associations::Preloader
- Object
- ActiveRecord::Associations::Preloader
- Dase::Preloader
- Defined in:
- lib/dase/preloader.rb
Defined Under Namespace
Classes: HasMany, HasManyThrough
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options) ⇒ Preloader
constructor
A new instance of Preloader.
-
#preloader_for(reflection, owners, rhs_klass) ⇒ Object
an overloaded version of ActiveRecord::Associations::Preloader’s preloader_for which returns a class of a custom preloader for a given association.
Constructor Details
#initialize(options) ⇒ Preloader
Returns a new instance of Preloader.
26 27 28 |
# File 'lib/dase/preloader.rb', line 26 def initialize() = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
24 25 26 |
# File 'lib/dase/preloader.rb', line 24 def end |
Instance Method Details
#preloader_for(reflection, owners, rhs_klass) ⇒ Object
an overloaded version of ActiveRecord::Associations::Preloader’s preloader_for which returns a class of a custom preloader for a given association
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dase/preloader.rb', line 32 def preloader_for(reflection, owners, rhs_klass) return NullPreloader unless rhs_klass if owners.first.association(reflection.name).loaded? return AlreadyLoaded end case reflection.macro when :has_many reflection.[:through] ? HasManyThrough : HasMany when :has_one, :belongs_to raise ArgumentError, "You can't use includes_count_of with a #{reflection.macro} association" else raise NotImplementedError, "#{reflection.macro} not supported" end end |