Class: Plucky::Query
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- Enumerable, DSL
- Defined in:
- lib/plucky/query.rb
Defined Under Namespace
Modules: DSL
Constant Summary
collapse
- OptionKeys =
Set[
:select, :offset, :order, :fields, :skip, :limit, :sort, :hint, :snapshot, :batch_size, :timeout, :max_scan, :return_key, :transformer, :show_disk_loc, :comment, :read, :tag_sets, :acceptable_latency, ]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from DSL
#all, #count, #distinct, #empty?, #exists?, #fields, #find, #find_each, #find_one, #ignore, #last, #limit, #only, #paginate, #per_page, #remove, #reverse, #skip, #sort, #where
Constructor Details
#initialize(collection, query_options = {}) ⇒ Query
26
27
28
29
|
# File 'lib/plucky/query.rb', line 26
def initialize(collection, query_options = {})
@collection, @options, @criteria = collection, OptionsHash.new, CriteriaHash.new
query_options.each { |key, value| self[key] = value }
end
|
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
19
20
21
|
# File 'lib/plucky/query.rb', line 19
def collection
@collection
end
|
Returns the value of attribute criteria.
19
20
21
|
# File 'lib/plucky/query.rb', line 19
def criteria
@criteria
end
|
Returns the value of attribute options.
19
20
21
|
# File 'lib/plucky/query.rb', line 19
def options
@options
end
|
Instance Method Details
191
192
193
194
195
|
# File 'lib/plucky/query.rb', line 191
def [](key)
key = symbolized_key(key)
source = hash_for_key(key)
source[key]
end
|
#[]=(key, value) ⇒ Object
197
198
199
200
201
|
# File 'lib/plucky/query.rb', line 197
def []=(key, value)
key = symbolized_key(key)
source = hash_for_key(key)
source[key] = value
end
|
#amend(opts = {}) ⇒ Object
186
187
188
189
|
# File 'lib/plucky/query.rb', line 186
def amend(opts={})
opts.each { |key, value| self[key] = value }
self
end
|
#criteria_hash ⇒ Object
224
225
226
|
# File 'lib/plucky/query.rb', line 224
def criteria_hash
@criteria.to_hash
end
|
232
233
234
|
# File 'lib/plucky/query.rb', line 232
def cursor
@collection.find(criteria_hash, options_hash)
end
|
213
214
215
|
# File 'lib/plucky/query.rb', line 213
def explain
@collection.find(criteria_hash, options_hash).explain
end
|
#initialize_copy(original) ⇒ Object
31
32
33
34
35
|
# File 'lib/plucky/query.rb', line 31
def initialize_copy(original)
super
@criteria = @criteria.dup
@options = @options.dup
end
|
217
218
219
220
221
222
|
# File 'lib/plucky/query.rb', line 217
def inspect
as_nice_string = to_hash.collect do |key, value|
" #{key}: #{value.inspect}"
end.sort.join(",")
"#<#{self.class}#{as_nice_string}>"
end
|
#merge(other) ⇒ Object
203
204
205
206
207
|
# File 'lib/plucky/query.rb', line 203
def merge(other)
merged_criteria = @criteria.merge(other.criteria).to_hash
merged_options = @options.merge(other.options).to_hash
clone.amend(merged_criteria).amend(merged_options)
end
|
#object_ids(*keys) ⇒ Object
38
39
40
41
42
|
# File 'lib/plucky/query.rb', line 38
def object_ids(*keys)
return @criteria.object_ids if keys.empty?
@criteria.object_ids = *keys
self
end
|
#options_hash ⇒ Object
228
229
230
|
# File 'lib/plucky/query.rb', line 228
def options_hash
@options.to_hash
end
|
209
210
211
|
# File 'lib/plucky/query.rb', line 209
def to_hash
criteria_hash.merge(options_hash)
end
|
#update(document, driver_opts = {}) ⇒ Object
181
182
183
184
|
# File 'lib/plucky/query.rb', line 181
def update(document, driver_opts={})
query = clone
query.collection.update(query.criteria_hash, document, driver_opts)
end
|