Class: Pagify::ActiveRecordPager

Inherits:
BasicPager show all
Includes:
PageAcceptStringOrBlank
Defined in:
lib/pagify/pager/active_record.rb

Overview

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’

Instance Attribute Summary collapse

Attributes inherited from BasicPager

#counter, #fetcher, #opts

Instance Method Summary collapse

Methods inherited from BasicPager

#==, #each, #entries_count, #offset, #page, #page_exists?, #size, #to_a

Constructor Details

#initialize(model_class, opts = {}) ⇒ ActiveRecordPager

Returns a new instance of ActiveRecordPager.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pagify/pager/active_record.rb', line 17

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

Instance Attribute Details

#modelObject (readonly)

the model class that you passed in this paginator



15
16
17
# File 'lib/pagify/pager/active_record.rb', line 15

def model
  @model
end