Class: Finexclub::Manager::Cursor
- Inherits:
-
Object
- Object
- Finexclub::Manager::Cursor
- Includes:
- Enumerable
- Defined in:
- lib/finexclub/manager.rb
Instance Attribute Summary collapse
-
#core ⇒ Object
readonly
Returns the value of attribute core.
-
#mongo_cursor ⇒ Object
Returns the value of attribute mongo_cursor.
Instance Method Summary collapse
- #current_limit ⇒ Object
- #current_skip ⇒ Object
- #each ⇒ Object
-
#empty? ⇒ Boolean
Is the cursor empty? This method is much more efficient than doing cursor.count == 0.
-
#initialize(core, obj_class, mongo_cursor) ⇒ Cursor
constructor
A new instance of Cursor.
- #limit(number_to_return) ⇒ Object
- #next_document ⇒ Object (also: #next)
- #skip(number_to_skip) ⇒ Object
- #sort(key_or_list, direction = nil) ⇒ Object
Constructor Details
#initialize(core, obj_class, mongo_cursor) ⇒ Cursor
Returns a new instance of Cursor.
80 81 82 83 84 |
# File 'lib/finexclub/manager.rb', line 80 def initialize(core, obj_class, mongo_cursor) @core = core @obj_class = obj_class @mongo_cursor = mongo_cursor end |
Instance Attribute Details
#core ⇒ Object (readonly)
Returns the value of attribute core.
78 79 80 |
# File 'lib/finexclub/manager.rb', line 78 def core @core end |
#mongo_cursor ⇒ Object
Returns the value of attribute mongo_cursor.
77 78 79 |
# File 'lib/finexclub/manager.rb', line 77 def mongo_cursor @mongo_cursor end |
Instance Method Details
#current_limit ⇒ Object
113 114 115 |
# File 'lib/finexclub/manager.rb', line 113 def current_limit @mongo_cursor.limit end |
#current_skip ⇒ Object
121 122 123 |
# File 'lib/finexclub/manager.rb', line 121 def current_skip @mongo_cursor.skip end |
#each ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/finexclub/manager.rb', line 105 def each @mongo_cursor.each do |doc| obj = @obj_class.new(core) obj.build(doc) yield(obj) end end |
#empty? ⇒ Boolean
Is the cursor empty? This method is much more efficient than doing cursor.count == 0
91 92 93 |
# File 'lib/finexclub/manager.rb', line 91 def empty? @mongo_cursor.has_next? == false end |
#limit(number_to_return) ⇒ Object
117 118 119 |
# File 'lib/finexclub/manager.rb', line 117 def limit(number_to_return) @mongo_cursor.limit(number_to_return); self end |
#next_document ⇒ Object Also known as: next
95 96 97 98 99 100 101 |
# File 'lib/finexclub/manager.rb', line 95 def next_document if doc = @mongo_cursor.next_document obj = @obj_class.new(core) obj.build(doc) obj end end |
#skip(number_to_skip) ⇒ Object
125 126 127 |
# File 'lib/finexclub/manager.rb', line 125 def skip(number_to_skip) @mongo_cursor.skip(number_to_skip); self end |
#sort(key_or_list, direction = nil) ⇒ Object
129 130 131 |
# File 'lib/finexclub/manager.rb', line 129 def sort(key_or_list, direction = nil) @mongo_cursor.sort(key_or_list, direction); self end |