Class: RRepo::Adapters::Mongo::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/rrepo/adapters/mongo.rb

Overview

A Mongo Query object

Instance Method Summary collapse

Constructor Details

#initialize(collection, &block) ⇒ Query

Returns a new instance of Query.



45
46
47
48
49
# File 'lib/rrepo/adapters/mongo.rb', line 45

def initialize(collection, &block)
  @collection = collection
  @query = [{}]
  instance_eval(&block) if block_given?
end

Instance Method Details

#orObject



56
57
58
59
# File 'lib/rrepo/adapters/mongo.rb', line 56

def or
  @query << {}
  self
end

#runObject



61
62
63
64
65
66
67
# File 'lib/rrepo/adapters/mongo.rb', line 61

def run
  if @query.size > 1
    @collection.find(:$or => @query)
  else
    @collection.find(@query.first)
  end
end

#to_hashObject



69
70
71
# File 'lib/rrepo/adapters/mongo.rb', line 69

def to_hash
  @query
end

#where(condition) ⇒ Object



51
52
53
54
# File 'lib/rrepo/adapters/mongo.rb', line 51

def where(condition)
  @query.last.merge!(condition)
  self
end