class MongoModel::InstrumentedCollection
Attributes
collection[R]
Public Class Methods
new(collection)
click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 45 def initialize(collection) @collection = collection end
Public Instance Methods
==(other)
click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 49 def ==(other) case other when self.class collection == other.collection else collection == other end end
create_index(spec, options={})
click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 95 def create_index(spec, options={}) instrument("create_index(#{spec.inspect})") do collection.create_index(spec, options) end end
distinct(key, query=nil)
click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 107 def distinct(key, query=nil) instrument("distinct(#{key.inspect}#{query.present? ? ', ' + query.inspect : ''})") do collection.distinct(key, query) end end
find(selector={}, options={}) { |cursor| ... }
click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 58 def find(selector={}, options={}) cursor = InstrumentedCursor.new(collection.find(selector, options)) if block_given? yield cursor cursor.close nil else cursor end end
group(options, condition={}, initial={}, reduce=nil, finalize=nil)
click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 101 def group(options, condition={}, initial={}, reduce=nil, finalize=nil) instrument("group(#{options.inspect})") do collection.group(options, condition, initial, reduce, finalize) end end
map_reduce(map, reduce, options={})
click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 113 def map_reduce(map, reduce, options={}) instrument("map_reduce(#{options.inspect})") do collection.map_reduce(map, reduce, options) end end
remove(selector={}, options={})
click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 83 def remove(selector={}, options={}) instrument("remove(#{selector.inspect})") do collection.remove(selector, options) end end
save(doc, options={})
click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 70 def save(doc, options={}) if doc.has_key?(:_id) || doc.has_key?('_id') selector = { '_id' => doc[:_id] || doc['_id'] } instrument("update(#{selector.inspect}, #{doc.inspect})") do collection.save(doc, options) end else instrument("insert(#{doc})") do collection.insert(doc, options) end end end
update(selector, document, options={})
click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 89 def update(selector, document, options={}) instrument("update(#{selector.inspect}, #{document.inspect})") do collection.update(selector, document, options) end end
Private Instance Methods
instrument(query, &block)
click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 124 def instrument(query, &block) ActiveSupport::Notifications.instrument("query.mongomodel", :collection => collection.name, :query => query, &block) end
method_missing(method, *args, &block)
click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 120 def method_missing(method, *args, &block) collection.send(method, *args, &block) end