Class: RRepo::Adapters::Mongo::Query
- Inherits:
-
Object
- Object
- RRepo::Adapters::Mongo::Query
- Defined in:
- lib/rrepo/adapters/mongo.rb
Overview
A Mongo Query object
Instance Method Summary collapse
-
#initialize(collection, &block) ⇒ Query
constructor
A new instance of Query.
- #or ⇒ Object
- #run ⇒ Object
- #to_hash ⇒ Object
- #where(condition) ⇒ Object
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
#or ⇒ Object
56 57 58 59 |
# File 'lib/rrepo/adapters/mongo.rb', line 56 def or @query << {} self end |
#run ⇒ Object
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_hash ⇒ Object
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 |