Sha256: 76318fa36caa8105288d1144877550427d22959a1b3c0450ad8c0980f1b49b33

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

# you'll need activerecord to use ActiveRecordPager

module Pagify
  # active_record paginator was provided for convenience,
  # it wraps Paginator for you, and you can just pass the model class to it.
  # you don't have to care about the fetcher and counter.
  # additionally, you can pass other options to rails paginator,
  # they would be used in find options. e.g.,
  #  ActiveRecordPaginator.new Model, :order => 'created_at DESC'
  # would invoke Model.find :all, :offset => ?, :limit => ?, order => 'created_at DESC'
  class ActiveRecordPager < BasicPager
    include PageAcceptStringOrBlank
    # the model class that you passed in this paginator
    attr_reader :model

    def initialize model_class, opts = {}
      @model = model_class
      query_opts = reject_pager_opts(opts)

      super(opts.merge(
        :fetcher => lambda{ |offset, per_page|
          model.find(:all, query_opts.merge(:offset => offset, :limit => per_page))
        },
        :counter => lambda{
          model.count(query_opts)
        }))
    end
  end # of ActiveRecordPager
end # of Pagify

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
godfat-pagify-0.6.1 lib/pagify/pager/active_record.rb
godfat-pagify-0.6.2 lib/pagify/pager/active_record.rb
pagify-0.8.0 lib/pagify/pager/active_record.rb
pagify-0.7.1 lib/pagify/pager/active_record.rb
pagify-0.7.0 lib/pagify/pager/active_record.rb
pagify-0.6.2 lib/pagify/pager/active_record.rb
pagify-0.6.1 lib/pagify/pager/active_record.rb