Class: MongoMapper::Query

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
lib/mongo_mapper/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/mongo_mapper/query.rb', line 7

def model
  @model
end

#queryObject (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

#reverseObject



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

#spawnObject



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