Class: MongoMapper::Pagination::PaginationProxy
- Inherits:
- BasicObject
- 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.
8 9 10 11 12 |
# File 'lib/mongo_mapper/pagination.rb', line 8 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
36 37 38 |
# File 'lib/mongo_mapper/pagination.rb', line 36 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.
5 6 7 |
# File 'lib/mongo_mapper/pagination.rb', line 5 def current_page @current_page end |
#per_page ⇒ Object Also known as: limit
Returns the value of attribute per_page.
5 6 7 |
# File 'lib/mongo_mapper/pagination.rb', line 5 def per_page @per_page end |
#subject ⇒ Object
Returns the value of attribute subject.
4 5 6 |
# File 'lib/mongo_mapper/pagination.rb', line 4 def subject @subject end |
#total_entries ⇒ Object (readonly)
Returns the value of attribute total_entries.
5 6 7 |
# File 'lib/mongo_mapper/pagination.rb', line 5 def total_entries @total_entries end |
Instance Method Details
#next_page ⇒ Object
26 27 28 |
# File 'lib/mongo_mapper/pagination.rb', line 26 def next_page current_page < total_pages ? (current_page + 1) : nil end |
#out_of_bounds? ⇒ Boolean
18 19 20 |
# File 'lib/mongo_mapper/pagination.rb', line 18 def out_of_bounds? current_page > total_pages end |
#previous_page ⇒ Object
22 23 24 |
# File 'lib/mongo_mapper/pagination.rb', line 22 def previous_page current_page > 1 ? (current_page - 1) : nil end |
#skip ⇒ Object Also known as: offset
30 31 32 |
# File 'lib/mongo_mapper/pagination.rb', line 30 def skip (current_page - 1) * per_page end |
#total_pages ⇒ Object
14 15 16 |
# File 'lib/mongo_mapper/pagination.rb', line 14 def total_pages (total_entries / per_page.to_f).ceil end |