Class: ResqueCleaner::Server::Paginate
- Inherits:
-
Object
- Object
- ResqueCleaner::Server::Paginate
- Defined in:
- lib/resque_cleaner/server.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.
18 19 20 21 22 23 |
# File 'lib/resque_cleaner/server.rb', line 18 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.
17 18 19 |
# File 'lib/resque_cleaner/server.rb', line 17 def jobs @jobs end |
#page ⇒ Object
Returns the value of attribute page.
17 18 19 |
# File 'lib/resque_cleaner/server.rb', line 17 def page @page end |
#page_size ⇒ Object
Returns the value of attribute page_size.
17 18 19 |
# File 'lib/resque_cleaner/server.rb', line 17 def page_size @page_size end |
#url ⇒ Object
Returns the value of attribute url.
17 18 19 |
# File 'lib/resque_cleaner/server.rb', line 17 def url @url end |
Instance Method Details
#first_index ⇒ Object
25 26 27 |
# File 'lib/resque_cleaner/server.rb', line 25 def first_index @page_size * (@page-1) end |
#first_page? ⇒ Boolean
38 39 40 |
# File 'lib/resque_cleaner/server.rb', line 38 def first_page? @page <= 1 end |
#last_index ⇒ Object
29 30 31 32 |
# File 'lib/resque_cleaner/server.rb', line 29 def last_index last = first_index + @page_size - 1 last > @jobs.size-1 ? @jobs.size-1 : last end |
#last_page? ⇒ Boolean
42 43 44 |
# File 'lib/resque_cleaner/server.rb', line 42 def last_page? @page >= max_page end |
#max_page ⇒ Object
60 61 62 |
# File 'lib/resque_cleaner/server.rb', line 60 def max_page ((total_size-1) / @page_size) + 1 end |
#page_url(page) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/resque_cleaner/server.rb', line 46 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
34 35 36 |
# File 'lib/resque_cleaner/server.rb', line 34 def paginated_jobs @jobs[first_index,@page_size] end |
#total_size ⇒ Object
56 57 58 |
# File 'lib/resque_cleaner/server.rb', line 56 def total_size @jobs.size end |