Class: Pagify::DataMapperPager

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

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 = {}, query = {}) ⇒ DataMapperPager

Returns a new instance of DataMapperPager.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pagify/pager/data_mapper.rb', line 10

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

  super(opts.merge(
    :fetcher => lambda{ |offset, per_page|
      model.send :with_scope, query do
        model.all(query_opts.merge(:offset => offset, :limit => per_page))
      end
    },
    :counter => lambda{
      model.send :with_scope, query do
        model.count(query_opts)
      end
    }))
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



8
9
10
# File 'lib/pagify/pager/data_mapper.rb', line 8

def model
  @model
end