Class: Mingo::Cursor
- Inherits:
-
Mongo::Cursor
- Object
- Mongo::Cursor
- Mingo::Cursor
show all
- Defined in:
- lib/mingo/cursor.rb
Overview
Custom Cursor subclass. TODO: contribute this to the official driver
Defined Under Namespace
Modules: CollectionPlugin
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.from_mongo(cursor) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/mingo/cursor.rb', line 19
def self.from_mongo(cursor)
new(cursor.collection).tap do |sub|
cursor.instance_variables.each { |ivar|
sub.instance_variable_set(ivar, cursor.instance_variable_get(ivar))
}
end
end
|
Instance Method Details
#by_ids? ⇒ Boolean
31
32
33
|
# File 'lib/mingo/cursor.rb', line 31
def by_ids?
Hash === selector[:_id] && selector[:_id]["$in"]
end
|
#empty? ⇒ Boolean
27
28
29
|
# File 'lib/mingo/cursor.rb', line 27
def empty?
!has_next?
end
|
#reverse ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/mingo/cursor.rb', line 35
def reverse
check_modifiable
if by_ids? and !order
selector[:_id]["$in"] = selector[:_id]["$in"].reverse
self
elsif order && (!(Array === order) || !(Array === order.first) || order.size == 1)
if Array === order
field, dir = *order.flatten
dir = Mongo::Conversions::ASCENDING_CONVERSION.include?(dir.to_s) ? -1 : 1
else
field = order
dir = -1
end
sort(field, dir)
else
raise "can't reverse complex query"
end
end
|