Class: Mongoo::Cursor

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/mongoo/cursor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj_class, mongo_cursor) ⇒ Cursor

Returns a new instance of Cursor.


7
8
9
10
# File 'lib/mongoo/cursor.rb', line 7

def initialize(obj_class, mongo_cursor)
  @obj_class    = obj_class
  @mongo_cursor = mongo_cursor
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object


61
62
63
64
65
66
67
# File 'lib/mongoo/cursor.rb', line 61

def method_missing(name, *args)
  if @mongo_cursor.respond_to?(name)
    @mongo_cursor.send name, *args
  else
    super
  end
end

Instance Attribute Details

#mongo_cursorObject

Returns the value of attribute mongo_cursor


5
6
7
# File 'lib/mongoo/cursor.rb', line 5

def mongo_cursor
  @mongo_cursor
end

Instance Method Details

#batch_size(size = 0) ⇒ Object


56
57
58
59
# File 'lib/mongoo/cursor.rb', line 56

def batch_size(size=0)
  @mongo_cursor.batch_size(size)
  self
end

#countObject


37
38
39
# File 'lib/mongoo/cursor.rb', line 37

def count
  @mongo_cursor.count
end

#eachObject


22
23
24
25
26
27
28
# File 'lib/mongoo/cursor.rb', line 22

def each
  @mongo_cursor.each do |doc|
    obj = @obj_class.new(doc, true)
    Mongoo::IdentityMap.write(obj) if Mongoo::IdentityMap.on?
    yield obj
  end
end

#limit(number_to_return = nil) ⇒ Object


46
47
48
49
# File 'lib/mongoo/cursor.rb', line 46

def limit(number_to_return=nil)
  @mongo_cursor.limit(number_to_return)
  self
end

#next_documentObject Also known as: next


12
13
14
15
16
17
18
# File 'lib/mongoo/cursor.rb', line 12

def next_document
  if doc = @mongo_cursor.next_document
    obj = @obj_class.new(doc, true)
    Mongoo::IdentityMap.write(obj) if Mongoo::IdentityMap.on?
    obj
  end
end

#skip(number_to_return = nil) ⇒ Object


51
52
53
54
# File 'lib/mongoo/cursor.rb', line 51

def skip(number_to_return=nil)
  @mongo_cursor.skip(number_to_return)
  self
end

#sort(key_or_list, direction = nil) ⇒ Object


41
42
43
44
# File 'lib/mongoo/cursor.rb', line 41

def sort(key_or_list, direction=nil)
  @mongo_cursor.sort(key_or_list, direction)
  self
end

#to_aObject


30
31
32
33
34
35
# File 'lib/mongoo/cursor.rb', line 30

def to_a
  arr = @mongo_cursor.to_a.collect { |doc| @obj_class.new(doc, true) }
  if Mongoo::IdentityMap.on?
    arr.each { |obj| Mongoo::IdentityMap.write(obj) }
  end; arr
end