Sha256: 8cf926559fd429fc1d0a60213eac881687507f8e82d294d08f41614212cb68db

Contents?: true

Size: 804 Bytes

Versions: 9

Compression:

Stored size: 804 Bytes

Contents

module Kaminari
  module PageScopeMethods
    extend ActiveSupport::Concern
    module InstanceMethods
      # Specify the <tt>per_page</tt> value for the preceding <tt>page</tt> scope
      #   Model.page(3).per(10)
      def per(num)
        if (n = num.to_i) <= 0
          self
        else
          limit(n).offset(offset_value / limit_value * n)
        end
      end

      # Total number of pages
      def num_pages
        (total_count.to_f / limit_value).ceil
      end

      # Current page number
      def current_page
        (offset_value / limit_value) + 1
      end

      # First page of the collection ?
      def first_page?
        current_page == 1
      end

      # Last page of the collection?
      def last_page?
        current_page >= num_pages
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 4 rubygems

Version Path
wulffeld_kaminari-0.12.4.2 lib/kaminari/models/page_scope_methods.rb
wulffeld_kaminari-0.12.4.1 lib/kaminari/models/page_scope_methods.rb
sayso-kaminari-0.12.4.001 lib/kaminari/models/page_scope_methods.rb
dimkiriyenko-kaminari-0.12.6 lib/kaminari/models/page_scope_methods.rb
dimkiriyenko-kaminari-0.12.5 lib/kaminari/models/page_scope_methods.rb
dimkiriyenko-kaminari-0.12.4 lib/kaminari/models/page_scope_methods.rb
kaminari-0.12.4 lib/kaminari/models/page_scope_methods.rb
kaminari-0.12.3 lib/kaminari/models/page_scope_methods.rb
kaminari-0.12.2 lib/kaminari/models/page_scope_methods.rb