Class: MongoMapper::Plugins::Pagination::Proxy
- Inherits:
-
Object
- Object
- MongoMapper::Plugins::Pagination::Proxy
show all
- Defined in:
- lib/mongo_mapper/plugins/pagination/proxy.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(total_entries, current_page, per_page = nil) ⇒ Proxy
Returns a new instance of Proxy.
12
13
14
15
16
|
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 12
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
51
52
53
|
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 51
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.
9
10
11
|
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 9
def current_page
@current_page
end
|
#per_page ⇒ Object
Also known as:
limit
Returns the value of attribute per_page.
9
10
11
|
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 9
def per_page
@per_page
end
|
Returns the value of attribute subject.
8
9
10
|
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 8
def subject
@subject
end
|
#total_entries ⇒ Object
Returns the value of attribute total_entries.
9
10
11
|
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 9
def total_entries
@total_entries
end
|
Instance Method Details
#===(other) ⇒ Object
47
48
49
|
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 47
def ===(other)
other === subject
end
|
#next_page ⇒ Object
30
31
32
|
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 30
def next_page
current_page < total_pages ? (current_page + 1) : nil
end
|
#out_of_bounds? ⇒ Boolean
22
23
24
|
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 22
def out_of_bounds?
current_page > total_pages
end
|
#previous_page ⇒ Object
26
27
28
|
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 26
def previous_page
current_page > 1 ? (current_page - 1) : nil
end
|
#respond_to?(name, *args, &block) ⇒ Boolean
55
56
57
|
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 55
def respond_to?(name, *args, &block)
super || @subject.respond_to?(name, *args, &block)
end
|
#send(method, *args, &block) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 39
def send(method, *args, &block)
if respond_to?(method)
super
else
subject.send(method, *args, &block)
end
end
|
#skip ⇒ Object
Also known as:
offset
34
35
36
|
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 34
def skip
(current_page - 1) * per_page
end
|
#total_pages ⇒ Object
18
19
20
|
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 18
def total_pages
(total_entries / per_page.to_f).ceil
end
|