Sha256: cf116f7756c9c41a306116a31a27a33739ab15c5586270bc233a12b7672a0da7

Contents?: true

Size: 730 Bytes

Versions: 3

Compression:

Stored size: 730 Bytes

Contents

module RailsPagination
  module ActiveRecord
    module Base

      def inherited(subclass)
        if subclass.superclass == ::ActiveRecord::Base
          subclass.scope :page, Proc.new {|number|
            subclass.limit(subclass.default_per_page).offset(subclass.default_per_page * ([number.to_i, 1].max - 1))
          } do
            include RailsPagination::ActiveRecord::Relation
          end
        end       
      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.7 lib/rails_pagination/active_record/base.rb
rails_pagination-2.0.6 lib/rails_pagination/active_record/base.rb
rails_pagination-2.0.5 lib/rails_pagination/active_record/base.rb