Sha256: e0d972428514b1a9579f45e6a0f307b0baedeb3465f7d853a81add836bd3b206

Contents?: true

Size: 750 Bytes

Versions: 3

Compression:

Stored size: 750 Bytes

Contents

module RailsPagination
  module ActiveRecord
    module Base

      def inherited(subclass)
        subclass.class_eval do
          if superclass == ::ActiveRecord::Base
            scope :page, Proc.new { |number|
              limit(default_per_page).offset(default_per_page * ([number.to_i, 1].max - 1))
            } do
              include RailsPagination::ActiveRecord::Relation
            end
          end
        end
        super
      end

      def default_per_page(value=nil)
        unless value.nil?
          value = [value.to_i, 1].max
          @default_per_page = value
        end
        defined?(@default_per_page).nil? ? Rails.application.config.pagination.default_per_page : @default_per_page 
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rails_pagination-2.0.10 lib/rails_pagination/active_record/base.rb
rails_pagination-2.0.9 lib/rails_pagination/active_record/base.rb
rails_pagination-2.0.8 lib/rails_pagination/active_record/base.rb