Sha256: f08607572d6d74a99576ef9a7dc6b0b05636d99c9da54eecd03d327d6e4f6e4a

Contents?: true

Size: 814 Bytes

Versions: 2

Compression:

Stored size: 814 Bytes

Contents

module EdgeRider
  module PreloadAssociations
    module PreloadAssociationsInstanceMethod
      def preload_associations(*args)
        self.class.preload_associations([self], *args)
      end
    end

    def preload_associations(*args)
      preloader = ActiveRecord::Associations::Preloader

      if preloader.method_defined?(:preload) # Rails 4
        preloader.new.preload(*args)
      else
        preloader.new(*args).run
      end
    end

    if ActiveRecord::Base.respond_to?(:preload_associations, true) # Rails 2/3.0
      ActiveRecord::Base.class_eval do
        class << self
          public :preload_associations
        end
      end
    else # Rails 3.2+
      ActiveRecord::Base.send(:extend, self)
    end

    ActiveRecord::Base.send(:include, PreloadAssociationsInstanceMethod)

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
edge_rider-2.0.0 lib/edge_rider/preload_associations.rb
edge_rider-1.1.0 lib/edge_rider/preload_associations.rb