class MongoModel::InstrumentedCursor

Attributes

cursor[R]

Public Class Methods

new(cursor) click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 10
def initialize(cursor)
  @cursor = cursor
end

Public Instance Methods

count() click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 20
def count
  instrument("count(#{cursor.selector.inspect})") do
    cursor.count
  end
end
to_a() click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 14
def to_a
  instrument(query_description) do
    cursor.to_a
  end
end

Private Instance Methods

instrument(query, &block) click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 37
def instrument(query, &block)
  ActiveSupport::Notifications.instrument("query.mongomodel", :collection => cursor.collection.name, :query => query, &block)
end
method_missing(method, *args, &block) click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 27
def method_missing(method, *args, &block)
  cursor.send(method, *args, &block)
end
query_description() click to toggle source
# File lib/mongomodel/support/instrumented_collection.rb, line 31
def query_description
  "find(#{cursor.selector.inspect}, #{cursor.fields ? cursor.fields.inspect : '{}'})" +
  "#{cursor.skip != 0 ? ('.skip(' + cursor.skip.to_s + ')') : ''}#{cursor.limit != 0 ? ('.limit(' + cursor.limit.to_s + ')') : ''}" +
  "#{cursor.order ? ('.sort(' + cursor.order.inspect + ')') : ''}"
end