class Mongorilla::Cursor

Public Class Methods

new(klass,cursor,col,cond,opt) click to toggle source
# File lib/mongorilla/cursor.rb, line 41
def initialize(klass,cursor,col,cond,opt)
  @members = {}
  @klass = klass
  @cursor = cursor
  @col = col
  @cond = cond
  @opt = opt
end

Public Instance Methods

[](idx) click to toggle source
# File lib/mongorilla/cursor.rb, line 5
def [](idx)
  if idx < 0
    idx = @cursor.count + idx
    return nil if idx < 0
  else
    return nil if idx >= @cursor.count
  end
  return @members[idx] if @members[idx]
  ret = @cursor.skip(idx).limit(1).first
  @cursor = @col.find(@cond,@opt)
  @members[idx] = ret ? @klass.new(ret) : nil
end
count() click to toggle source
# File lib/mongorilla/cursor.rb, line 37
def count
  @cursor.count
end
each() { |klass| ... } click to toggle source
# File lib/mongorilla/cursor.rb, line 31
def each
  @cursor.each do|v|
    yield @klass.new(v)
  end
end
to_a() click to toggle source
# File lib/mongorilla/cursor.rb, line 18
def to_a
  @cursor.map{|c| @klass.new(c)}
end
to_json() click to toggle source
# File lib/mongorilla/cursor.rb, line 27
def to_json
  to_a().map(&:to_hash).to_json
end
to_yaml() click to toggle source
# File lib/mongorilla/cursor.rb, line 23
def to_yaml
  to_a().map(&:to_hash).to_yaml
end