Sha256: d9cbc0050aca8dd0c3dc7888d93232aa474612afba6a66902b341b21a62e84f9

Contents?: true

Size: 1.21 KB

Versions: 19

Compression:

Stored size: 1.21 KB

Contents

module Sunspot
  module Search

    class PaginatedCollection
      instance_methods.each { |m| undef_method m unless m =~ /^__|instance_eval|object_id/ }

      attr_reader :current_page, :per_page
      attr_accessor :total_count
      alias :total_entries :total_count
      alias :total_entries= :total_count=
      alias :limit_value :per_page

      def initialize(collection, page, per_page, total)
        @collection   = collection
        @current_page = page
        @per_page     = per_page
        @total_count  = total
      end

      def total_pages
        (total_count.to_f / per_page).ceil
      end
      alias :num_pages :total_pages

      def first_page?
        current_page == 1
      end

      def last_page?
        current_page >= total_pages
      end

      def previous_page
        current_page > 1 ? (current_page - 1) : nil
      end

      def next_page
        current_page < total_pages ? (current_page + 1) : nil
      end

      def out_of_bounds?
        current_page > total_pages
      end

      def offset
        (current_page - 1) * per_page
      end

      private

      def method_missing(method, *args, &block)
        @collection.send(method, *args, &block)
      end

    end
  end
end

Version data entries

19 entries across 19 versions & 6 rubygems

Version Path
gojee-sunspot-2.0.5 lib/sunspot/search/paginated_collection.rb
sunspot-2.0.0.pre.120925 lib/sunspot/search/paginated_collection.rb
sunspot_solr-2.0.0.pre.120924 sunspot/lib/sunspot/search/paginated_collection.rb
sunspot_rails-2.0.0.pre.120924 sunspot/lib/sunspot/search/paginated_collection.rb
sunspot-2.0.0.pre.120924 sunspot/lib/sunspot/search/paginated_collection.rb
gojee-sunspot-2.0.4 lib/sunspot/search/paginated_collection.rb
gojee-sunspot-2.0.2 lib/sunspot/search/paginated_collection.rb
sunspot-2.0.0.pre.120720 lib/sunspot/search/paginated_collection.rb
sunspot-2.0.0.pre.120417 lib/sunspot/search/paginated_collection.rb
sunspot-2.0.0.pre.120415 lib/sunspot/search/paginated_collection.rb
erichummel-sunspot-2.0.0.pre.111215d lib/sunspot/search/paginated_collection.rb
erichummel-sunspot-2.0.0.pre.111215c lib/sunspot/search/paginated_collection.rb
erichummel-sunspot-2.0.0.pre.111215b lib/sunspot/search/paginated_collection.rb
erichummel-sunspot-2.0.0.pre.111215a lib/sunspot/search/paginated_collection.rb
erichummel-sunspot-2.0.0.pre.111215 lib/sunspot/search/paginated_collection.rb
sunspot-2.0.0.pre.111215 lib/sunspot/search/paginated_collection.rb
cb_sunspot-2.0.0.pre.5 lib/sunspot/search/paginated_collection.rb
cb_sunspot-2.0.0.pre.3 lib/sunspot/search/paginated_collection.rb
cb_sunspot-2.0.0.pre3 lib/sunspot/search/paginated_collection.rb