Module: FmStore::Paging

Included in:
FmReader
Defined in:
lib/fm_store/paging.rb

Instance Method Summary collapse

Instance Method Details

#pageObject



18
19
20
21
# File 'lib/fm_store/paging.rb', line 18

def page
  skips, limits = options[:skip_records], options[:max_records]
  (skips && limits) ? (skips + limits) / limits : 1
end

#paginate(opts = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fm_store/paging.rb', line 4

def paginate(opts = {})
  options[:max_records] = opts[:per_page] || 30
  
  if opts[:page]
    options[:skip_records] = (opts[:page].to_i - 1) * options[:max_records].to_i
  end
  
  collection = execute(true)
  
  WillPaginate::Collection.create(page, per_page, count) do |pager|
    pager.replace(collection)
  end
end

#per_pageObject



23
24
25
# File 'lib/fm_store/paging.rb', line 23

def per_page
  (options[:max_records] || 30).to_i
end