Class: MongoMapper::Pagination::PaginationProxy
- Defined in:
- lib/mongo_mapper/pagination.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#per_page ⇒ Object
(also: #limit)
readonly
Returns the value of attribute per_page.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#total_entries ⇒ Object
readonly
Returns the value of attribute total_entries.
Instance Method Summary collapse
-
#initialize(total_entries, current_page, per_page = nil) ⇒ PaginationProxy
constructor
A new instance of PaginationProxy.
- #method_missing(name, *args, &block) ⇒ Object
- #next_page ⇒ Object
- #out_of_bounds? ⇒ Boolean
- #previous_page ⇒ Object
- #skip ⇒ Object (also: #offset)
- #total_pages ⇒ Object
Constructor Details
#initialize(total_entries, current_page, per_page = nil) ⇒ PaginationProxy
Returns a new instance of PaginationProxy.
10 11 12 13 14 |
# File 'lib/mongo_mapper/pagination.rb', line 10 def initialize(total_entries, current_page, per_page=nil) @total_entries = total_entries.to_i self.per_page = per_page self.current_page = current_page end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
38 39 40 |
# File 'lib/mongo_mapper/pagination.rb', line 38 def method_missing(name, *args, &block) @subject.send(name, *args, &block) end |
Instance Attribute Details
#current_page ⇒ Object
Returns the value of attribute current_page.
7 8 9 |
# File 'lib/mongo_mapper/pagination.rb', line 7 def current_page @current_page end |
#per_page ⇒ Object Also known as: limit
Returns the value of attribute per_page.
7 8 9 |
# File 'lib/mongo_mapper/pagination.rb', line 7 def per_page @per_page end |
#subject ⇒ Object
Returns the value of attribute subject.
6 7 8 |
# File 'lib/mongo_mapper/pagination.rb', line 6 def subject @subject end |
#total_entries ⇒ Object (readonly)
Returns the value of attribute total_entries.
7 8 9 |
# File 'lib/mongo_mapper/pagination.rb', line 7 def total_entries @total_entries end |
Instance Method Details
#next_page ⇒ Object
28 29 30 |
# File 'lib/mongo_mapper/pagination.rb', line 28 def next_page current_page < total_pages ? (current_page + 1) : nil end |
#out_of_bounds? ⇒ Boolean
20 21 22 |
# File 'lib/mongo_mapper/pagination.rb', line 20 def out_of_bounds? current_page > total_pages end |
#previous_page ⇒ Object
24 25 26 |
# File 'lib/mongo_mapper/pagination.rb', line 24 def previous_page current_page > 1 ? (current_page - 1) : nil end |
#skip ⇒ Object Also known as: offset
32 33 34 |
# File 'lib/mongo_mapper/pagination.rb', line 32 def skip (current_page - 1) * per_page end |
#total_pages ⇒ Object
16 17 18 |
# File 'lib/mongo_mapper/pagination.rb', line 16 def total_pages (total_entries / per_page.to_f).ceil end |