Class: Paginate
- Inherits:
-
Object
- Object
- Paginate
- Defined in:
- app/controllers/resque_controller.rb
Overview
Pagination helper for list page.
Instance Attribute Summary collapse
-
#jobs ⇒ Object
Returns the value of attribute jobs.
-
#page ⇒ Object
Returns the value of attribute page.
-
#page_size ⇒ Object
Returns the value of attribute page_size.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #first_index ⇒ Object
- #first_page? ⇒ Boolean
-
#initialize(jobs, url, page = 1, page_size = 20) ⇒ Paginate
constructor
A new instance of Paginate.
- #last_index ⇒ Object
- #last_page? ⇒ Boolean
- #max_page ⇒ Object
- #page_url(page) ⇒ Object
- #paginated_jobs ⇒ Object
- #total_size ⇒ Object
Constructor Details
#initialize(jobs, url, page = 1, page_size = 20) ⇒ Paginate
Returns a new instance of Paginate.
327 328 329 330 331 332 |
# File 'app/controllers/resque_controller.rb', line 327 def initialize(jobs, url, page=1, page_size=20) @jobs = jobs @url = url @page = (!page || page < 1) ? 1 : page @page_size = 20 end |
Instance Attribute Details
#jobs ⇒ Object
Returns the value of attribute jobs.
325 326 327 |
# File 'app/controllers/resque_controller.rb', line 325 def jobs @jobs end |
#page ⇒ Object
Returns the value of attribute page.
325 326 327 |
# File 'app/controllers/resque_controller.rb', line 325 def page @page end |
#page_size ⇒ Object
Returns the value of attribute page_size.
325 326 327 |
# File 'app/controllers/resque_controller.rb', line 325 def page_size @page_size end |
#url ⇒ Object
Returns the value of attribute url.
325 326 327 |
# File 'app/controllers/resque_controller.rb', line 325 def url @url end |
Instance Method Details
#first_index ⇒ Object
334 335 336 |
# File 'app/controllers/resque_controller.rb', line 334 def first_index @page_size * (@page-1) end |
#first_page? ⇒ Boolean
347 348 349 |
# File 'app/controllers/resque_controller.rb', line 347 def first_page? @page <= 1 end |
#last_index ⇒ Object
338 339 340 341 |
# File 'app/controllers/resque_controller.rb', line 338 def last_index last = first_index + @page_size - 1 last > @jobs.size-1 ? @jobs.size-1 : last end |
#last_page? ⇒ Boolean
351 352 353 |
# File 'app/controllers/resque_controller.rb', line 351 def last_page? @page >= max_page end |
#max_page ⇒ Object
369 370 371 |
# File 'app/controllers/resque_controller.rb', line 369 def max_page ((total_size-1) / @page_size) + 1 end |
#page_url(page) ⇒ Object
355 356 357 358 359 360 361 362 363 |
# File 'app/controllers/resque_controller.rb', line 355 def page_url(page) u = @url u += @url.include?("?") ? "&" : "?" if page.is_a?(Symbol) page = @page - 1 if page==:prev page = @page + 1 if page==:next end u += "p=#{page}" end |
#paginated_jobs ⇒ Object
343 344 345 |
# File 'app/controllers/resque_controller.rb', line 343 def paginated_jobs @jobs[first_index, @page_size] end |
#total_size ⇒ Object
365 366 367 |
# File 'app/controllers/resque_controller.rb', line 365 def total_size @jobs.size end |