Sha256: 882b99794da8cbb89c9cd162b02b75c44cc9649ceb694294e947788fb6b523a6

Contents?: true

Size: 1.54 KB

Versions: 12

Compression:

Stored size: 1.54 KB

Contents

module Makura
  module Plugin
    module Pager
      module SingletonMethods
        def pager(page, limit)
          Makura::Plugin::Pager::Pagination.new(self, :pager, page, limit)
        end
      end

      class Pagination
        def initialize(model, view, page, limit)
          @model, @view, @page, @limit = model, view, page, limit
        end

        # /pager/_all_docs?count=10&group=true
        # /pager/_all_docs?startkey=%224f9dca1c66121f9320a69553546db07a%22&startkey_docid=4f9dca1c66121f9320a69553546db07a&skip=1&descending=false&count=10&group=true
        # /pager/_all_docs?startkey=%22_design%2FUser%22&startkey_docid=_design%2FUser&skip=1&descending=false&count=10&group=true
        # /pager/_all_docs?startkey=%22d850f0801686b85035680bb6f38d5c5c%22&startkey_docid=d850f0801686b85035680bb6f38d5c5c&skip=1&descending=false&count=10&group=true

        # NOTE:
        #   * descending should be true if you page backwards

        include Enumerable

        def each(start_id = nil, descending = false, &block)
          opts = {
            :count => @limit,
            :group => true,
            :descending => descending,
            # :include_docs => true,
          }

          if start_id
            opts[:skip] = 1
            opts[:startkey_docid] = start_id
            opts[:startkey] = start_id
          end

          @model.view(@view, opts).each(&block)
        end

        def count
        end

        def first_page?
        end

        def last_page?
        end

        def empty?
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
careo-makura-0.1 lib/makura/plugin/pager.rb
careo-makura-2009.2.17 lib/makura/plugin/pager.rb
manveru-makura-2009.02.18 lib/makura/plugin/pager.rb
manveru-makura-2009.03.01 lib/makura/plugin/pager.rb
manveru-makura-2009.03.28 lib/makura/plugin/pager.rb
manveru-makura-2009.04.22 lib/makura/plugin/pager.rb
manveru-makura-2009.05.27 lib/makura/plugin/pager.rb
makura-2012.01 lib/makura/plugin/pager.rb
makura-2011.01.21 lib/makura/plugin/pager.rb
makura-2010.08.26 lib/makura/plugin/pager.rb
makura-2010.08 lib/makura/plugin/pager.rb
makura-2009.05.27 lib/makura/plugin/pager.rb