Class: MarkMapper::Query
Direct Known Subclasses
Defined Under Namespace
Modules: DSL
Constant Summary collapse
- OptionKeys =
Private
Set[ :select, :offset, :order, # MM :fields, :skip, :limit, :sort, # :hint, :snapshot, # Ruby Driver :debug, :return_results, :return_query, # Ruby Driver :format, :page, :per_page, :view, # Ruby Driver :transformer # Ruby Driver ]
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#criteria ⇒ Object
readonly
Returns the value of attribute criteria.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#amend(opts = {}) ⇒ Object
def update(document, driver_opts={}) query = clone query.collection.update(query.criteria_hash, document, driver_opts) end.
- #criteria_hash ⇒ Object
- #cursor(&block) ⇒ Object
- #explain ⇒ Object
-
#initialize(collection, query_options = {}) ⇒ Query
constructor
Public.
- #initialize_copy(original) ⇒ Object
- #inspect ⇒ Object
- #merge(other) ⇒ Object
-
#object_ids(*keys) ⇒ Object
Public.
- #options_hash ⇒ Object
- #to_hash ⇒ Object
Methods included from DSL
#all, #count, #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
Public
26 27 28 29 |
# File 'lib/mark_mapper/query.rb', line 26 def initialize(collection, = {}) @collection, , @criteria = collection, OptionsHash.new, CriteriaHash.new .each { |key, value| self[key] = value } end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
19 20 21 |
# File 'lib/mark_mapper/query.rb', line 19 def collection @collection end |
#criteria ⇒ Object (readonly)
Returns the value of attribute criteria.
19 20 21 |
# File 'lib/mark_mapper/query.rb', line 19 def criteria @criteria end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/mark_mapper/query.rb', line 19 def end |
Instance Method Details
#[](key) ⇒ Object
194 195 196 197 198 |
# File 'lib/mark_mapper/query.rb', line 194 def [](key) key = symbolized_key(key) source = hash_for_key(key) source[key] end |
#[]=(key, value) ⇒ Object
200 201 202 203 204 |
# File 'lib/mark_mapper/query.rb', line 200 def []=(key, value) key = symbolized_key(key) source = hash_for_key(key) source[key] = value end |
#amend(opts = {}) ⇒ Object
def update(document, driver_opts={})
query = clone
query.collection.update(query.criteria_hash, document, driver_opts)
end
189 190 191 192 |
# File 'lib/mark_mapper/query.rb', line 189 def amend(opts={}) opts.each { |key, value| self[key] = value } self end |
#criteria_hash ⇒ Object
227 228 229 |
# File 'lib/mark_mapper/query.rb', line 227 def criteria_hash @criteria.to_hash end |
#cursor(&block) ⇒ Object
235 236 237 |
# File 'lib/mark_mapper/query.rb', line 235 def cursor(&block) @collection.find(criteria_hash, , &block) end |
#explain ⇒ Object
216 217 218 |
# File 'lib/mark_mapper/query.rb', line 216 def explain @collection.find(query.criteria_hash, query.).explain end |
#initialize_copy(original) ⇒ Object
31 32 33 34 35 |
# File 'lib/mark_mapper/query.rb', line 31 def initialize_copy(original) super @criteria = @criteria.dup = .dup end |
#inspect ⇒ Object
220 221 222 223 224 225 |
# File 'lib/mark_mapper/query.rb', line 220 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
206 207 208 209 210 |
# File 'lib/mark_mapper/query.rb', line 206 def merge(other) merged_criteria = @criteria.merge(other.criteria).to_hash = .merge(other.).to_hash clone.amend(merged_criteria).amend() end |
#object_ids(*keys) ⇒ Object
Public
38 39 40 41 42 |
# File 'lib/mark_mapper/query.rb', line 38 def object_ids(*keys) return @criteria.object_ids if keys.empty? @criteria.object_ids = *keys self end |
#options_hash ⇒ Object
231 232 233 |
# File 'lib/mark_mapper/query.rb', line 231 def .to_hash end |
#to_hash ⇒ Object
212 213 214 |
# File 'lib/mark_mapper/query.rb', line 212 def to_hash criteria_hash.merge() end |