Class: Mongoid::QueryCounter
- Inherits:
-
Object
- Object
- Mongoid::QueryCounter
- Defined in:
- lib/mongoid/support/query_counter.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
Instance Method Summary collapse
-
#initialize ⇒ QueryCounter
constructor
A new instance of QueryCounter.
- #inspect ⇒ Object
- #instrument ⇒ Object
Constructor Details
#initialize ⇒ QueryCounter
Returns a new instance of QueryCounter.
6 7 8 |
# File 'lib/mongoid/support/query_counter.rb', line 6 def initialize @events = [] end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
4 5 6 |
# File 'lib/mongoid/support/query_counter.rb', line 4 def events @events end |
Instance Method Details
#inspect ⇒ Object
19 20 21 |
# File 'lib/mongoid/support/query_counter.rb', line 19 def inspect @events.map { |e| e.payload[:ops].map(&:log_inspect) }.join("\n") end |
#instrument ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/mongoid/support/query_counter.rb', line 10 def instrument subscriber = ActiveSupport::Notifications.subscribe('query.moped') do |*args| @events << ActiveSupport::Notifications::Event.new(*args) end yield ensure ActiveSupport::Notifications.unsubscribe(subscriber) end |