Class: MongoMapper::Plugins::Pagination::PaginationProxy
- Inherits:
-
Object
- Object
- MongoMapper::Plugins::Pagination::PaginationProxy
show all
- Defined in:
- lib/mongo_mapper/plugins/pagination.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(total_entries, current_page, per_page = nil) ⇒ PaginationProxy
Returns a new instance of PaginationProxy.
28
29
30
31
32
|
# File 'lib/mongo_mapper/plugins/pagination.rb', line 28
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
67
68
69
|
# File 'lib/mongo_mapper/plugins/pagination.rb', line 67
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.
25
26
27
|
# File 'lib/mongo_mapper/plugins/pagination.rb', line 25
def current_page
@current_page
end
|
#per_page ⇒ Object
Also known as:
limit
Returns the value of attribute per_page.
25
26
27
|
# File 'lib/mongo_mapper/plugins/pagination.rb', line 25
def per_page
@per_page
end
|
Returns the value of attribute subject.
24
25
26
|
# File 'lib/mongo_mapper/plugins/pagination.rb', line 24
def subject
@subject
end
|
#total_entries ⇒ Object
Returns the value of attribute total_entries.
25
26
27
|
# File 'lib/mongo_mapper/plugins/pagination.rb', line 25
def total_entries
@total_entries
end
|
Instance Method Details
#===(other) ⇒ Object
63
64
65
|
# File 'lib/mongo_mapper/plugins/pagination.rb', line 63
def ===(other)
other === subject
end
|
#next_page ⇒ Object
46
47
48
|
# File 'lib/mongo_mapper/plugins/pagination.rb', line 46
def next_page
current_page < total_pages ? (current_page + 1) : nil
end
|
#out_of_bounds? ⇒ Boolean
38
39
40
|
# File 'lib/mongo_mapper/plugins/pagination.rb', line 38
def out_of_bounds?
current_page > total_pages
end
|
#previous_page ⇒ Object
42
43
44
|
# File 'lib/mongo_mapper/plugins/pagination.rb', line 42
def previous_page
current_page > 1 ? (current_page - 1) : nil
end
|
#send(method, *args, &block) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/mongo_mapper/plugins/pagination.rb', line 55
def send(method, *args, &block)
if respond_to?(method)
super
else
subject.send(method, *args, &block)
end
end
|
#skip ⇒ Object
Also known as:
offset
50
51
52
|
# File 'lib/mongo_mapper/plugins/pagination.rb', line 50
def skip
(current_page - 1) * per_page
end
|
#total_pages ⇒ Object
34
35
36
|
# File 'lib/mongo_mapper/plugins/pagination.rb', line 34
def total_pages
(total_entries / per_page.to_f).ceil
end
|