Class: MongoidExt::Filter::ResultSet
- Inherits:
-
Object
- Object
- MongoidExt::Filter::ResultSet
show all
- Defined in:
- lib/mongoid_ext/filter/result_set.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#===(other) ⇒ Object
-
#initialize(total_entries, parsed_query, mongo_query, current_page, per_page = nil) ⇒ ResultSet
constructor
A new instance of ResultSet.
-
#method_missing(name, *args, &block) ⇒ Object
-
#next_page ⇒ Object
-
#out_of_bounds? ⇒ Boolean
-
#previous_page ⇒ Object
-
#respond_to?(name, *args, &block) ⇒ Boolean
-
#send(method, *args, &block) ⇒ Object
-
#skip ⇒ Object
(also: #offset)
-
#total_pages ⇒ Object
(also: #num_pages)
Constructor Details
#initialize(total_entries, parsed_query, mongo_query, current_page, per_page = nil) ⇒ ResultSet
Returns a new instance of ResultSet.
15
16
17
18
19
20
21
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 15
def initialize(total_entries, parsed_query, mongo_query, current_page, per_page=nil)
@total_entries = total_entries.to_i
@mongo_query = mongo_query
@parsed_query = parsed_query
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
57
58
59
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 57
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.
8
9
10
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 8
def current_page
@current_page
end
|
#mongo_query ⇒ Object
Returns the value of attribute mongo_query.
10
11
12
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 10
def mongo_query
@mongo_query
end
|
#parsed_query ⇒ Object
Returns the value of attribute parsed_query.
9
10
11
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 9
def parsed_query
@parsed_query
end
|
#per_page ⇒ Object
Also known as:
limit, limit_value
Returns the value of attribute per_page.
8
9
10
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 8
def per_page
@per_page
end
|
#subject ⇒ Object
Returns the value of attribute subject.
7
8
9
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 7
def subject
@subject
end
|
#total_entries ⇒ Object
Also known as:
total_count
Returns the value of attribute total_entries.
8
9
10
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 8
def total_entries
@total_entries
end
|
Instance Method Details
#===(other) ⇒ Object
53
54
55
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 53
def ===(other)
other === subject
end
|
#next_page ⇒ Object
36
37
38
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 36
def next_page
current_page < total_pages ? (current_page + 1) : nil
end
|
#out_of_bounds? ⇒ Boolean
28
29
30
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 28
def out_of_bounds?
current_page > total_pages
end
|
#previous_page ⇒ Object
32
33
34
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 32
def previous_page
current_page > 1 ? (current_page - 1) : nil
end
|
#respond_to?(name, *args, &block) ⇒ Boolean
61
62
63
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 61
def respond_to?(name, *args, &block)
super || @subject.respond_to?(name, *args, &block)
end
|
#send(method, *args, &block) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 45
def send(method, *args, &block)
if respond_to?(method)
super
else
subject.send(method, *args, &block)
end
end
|
#skip ⇒ Object
Also known as:
offset
40
41
42
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 40
def skip
(current_page - 1) * per_page
end
|
#total_pages ⇒ Object
Also known as:
num_pages
23
24
25
|
# File 'lib/mongoid_ext/filter/result_set.rb', line 23
def total_pages
(total_entries / per_page.to_f).ceil
end
|