Module: VORuby::ActiveVOTable::Pager
- Defined in:
- lib/voruby/active_votable/active_votable.rb
Overview
Paging methods for data.
Constant Summary collapse
- DEFAULT_PER_PAGE =
25
Instance Method Summary collapse
- #each_page(page_size = nil, options = {}) ⇒ Object
- #page(p = 1, page_size = nil, options = {}) ⇒ Object
- #per_page ⇒ Object
- #per_page=(n) ⇒ Object
Instance Method Details
#each_page(page_size = nil, options = {}) ⇒ Object
256 257 258 259 260 261 262 |
# File 'lib/voruby/active_votable/active_votable.rb', line 256 def each_page(page_size=nil, ={}) num_per_page = page_size || per_page (1..(count().to_f / num_per_page.to_f).ceil()).each do |n| yield(page(n, num_per_page), n) end end |
#page(p = 1, page_size = nil, options = {}) ⇒ Object
247 248 249 250 251 252 253 254 |
# File 'lib/voruby/active_votable/active_votable.rb', line 247 def page(p=1, page_size=nil, ={}) ||= {} [:limit] = page_size || per_page [:offset] = [:limit] * (p - 1) find(:all, ) end |
#per_page ⇒ Object
243 244 245 |
# File 'lib/voruby/active_votable/active_votable.rb', line 243 def per_page @per_page || DEFAULT_PER_PAGE end |
#per_page=(n) ⇒ Object
239 240 241 |
# File 'lib/voruby/active_votable/active_votable.rb', line 239 def per_page=(n) @per_page = n end |