Class: MongoMapper::Query
- Extended by:
- Forwardable
- Defined in:
- lib/mongo_mapper/query.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #all(opts = {}) ⇒ Object
- #fields(*args) ⇒ Object
- #first(opts = {}) ⇒ Object
-
#initialize(model) ⇒ Query
constructor
A new instance of Query.
- #initialize_copy(source) ⇒ Object
- #last(opts = {}) ⇒ Object
- #limit(*args) ⇒ Object
- #reverse ⇒ Object
- #skip(*args) ⇒ Object
- #sort(*args) ⇒ Object
- #spawn ⇒ Object
- #update(*args) ⇒ Object
- #where(*args) ⇒ Object
Constructor Details
#initialize(model) ⇒ Query
Returns a new instance of Query.
10 11 12 13 |
# File 'lib/mongo_mapper/query.rb', line 10 def initialize(model) @model = model @query = Plucky::Query.new(model.collection).object_ids(model.object_id_keys) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/mongo_mapper/query.rb', line 7 def model @model end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
7 8 9 |
# File 'lib/mongo_mapper/query.rb', line 7 def query @query end |
Instance Method Details
#all(opts = {}) ⇒ Object
20 21 22 |
# File 'lib/mongo_mapper/query.rb', line 20 def all(opts={}) spawn.update(opts).all.map { |doc| load(doc) } end |
#fields(*args) ⇒ Object
46 47 48 49 |
# File 'lib/mongo_mapper/query.rb', line 46 def fields(*args) query.fields(*args) self end |
#first(opts = {}) ⇒ Object
24 25 26 |
# File 'lib/mongo_mapper/query.rb', line 24 def first(opts={}) load(spawn.update(opts).first) end |
#initialize_copy(source) ⇒ Object
15 16 17 18 |
# File 'lib/mongo_mapper/query.rb', line 15 def initialize_copy(source) super @query = @query.clone end |
#last(opts = {}) ⇒ Object
28 29 30 |
# File 'lib/mongo_mapper/query.rb', line 28 def last(opts={}) load(spawn.update(opts).last) end |
#limit(*args) ⇒ Object
51 52 53 54 |
# File 'lib/mongo_mapper/query.rb', line 51 def limit(*args) query.limit(*args) self end |
#reverse ⇒ Object
66 67 68 69 |
# File 'lib/mongo_mapper/query.rb', line 66 def reverse query.reverse self end |
#skip(*args) ⇒ Object
56 57 58 59 |
# File 'lib/mongo_mapper/query.rb', line 56 def skip(*args) query.skip(*args) self end |
#sort(*args) ⇒ Object
61 62 63 64 |
# File 'lib/mongo_mapper/query.rb', line 61 def sort(*args) query.sort(*args) self end |
#spawn ⇒ Object
32 33 34 |
# File 'lib/mongo_mapper/query.rb', line 32 def spawn query.clone end |
#update(*args) ⇒ Object
36 37 38 39 |
# File 'lib/mongo_mapper/query.rb', line 36 def update(*args) query.update(*args) self end |
#where(*args) ⇒ Object
41 42 43 44 |
# File 'lib/mongo_mapper/query.rb', line 41 def where(*args) query.where(*args) self end |