class Dase::Preloader
Attributes
options[R]
Public Class Methods
new(options)
click to toggle source
# File lib/dase/preloader.rb, line 26 def initialize(options) @options = options end
Public Instance Methods
preloader_for(reflection, owners, rhs_klass)
click to toggle source
an overloaded version of ActiveRecord::Associations::Preloader's preloader_for
which returns a class of a custom preloader for a given association
# 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.options[: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