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
27
28
29
30
31
32
33
34
35
# File 'lib/pagify/pager/data_mapper.rb', line 10

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

  super(opts.merge(
    :fetcher => lambda{ |offset, per_page|
      # TODO: i am not sure why do we need this check?
      if query == model.query
        model.all(query_opts.merge(:offset => offset, :limit => per_page))
      else
        model.send(:with_scope, query) do
          model.all(query_opts.merge(:offset => offset, :limit => per_page))
        end
      end
    },
    :counter => lambda{
      # TODO: i am not sure why do we need this check?
      if query == model.query
        model.count(query_opts)
      else
        model.send(:with_scope, query) do
          model.count(query_opts)
        end
      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