Sha256: 35d8a66a4973f587670951944a27155a7b90892b43a7bbf99943dad20ff882c5

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

require File.join(File.dirname(__FILE__), 'active_record_relation_methods')
module Kaminari
  module ActiveRecordExtension
    extend ActiveSupport::Concern
    included do
      def self.inherited(kls) #:nodoc:
        # TERRIBLE HORRIBLE NO GOOD VERY BAD HACK: inheritable_attributes is not yet set here on AR 3.0
        unless kls.default_scoping
          new_inheritable_attributes = Hash[inheritable_attributes.map do |key, value|
            [key, value.duplicable? ? value.dup : value]
          end]
          kls.instance_variable_set('@inheritable_attributes', new_inheritable_attributes)
        end

        kls.class_eval do
          include Kaminari::ConfigurationMethods

          # Fetch the values at the specified page number
          #   Model.page(5)
          scope :page, Proc.new {|num|
            limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
          } do
            include Kaminari::ActiveRecordRelationMethods
            include Kaminari::PageScopeMethods
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kaminari-0.10.3 lib/kaminari/models/active_record_extension.rb
kaminari-0.10.2 lib/kaminari/models/active_record_extension.rb
kaminari-0.10.1 lib/kaminari/models/active_record_extension.rb
kaminari-0.10.0 lib/kaminari/models/active_record_extension.rb