Class: QueryMatchers::QueryCounter
- Inherits:
-
Object
- Object
- QueryMatchers::QueryCounter
- Defined in:
- lib/query_matchers/query_counter.rb
Constant Summary collapse
- OPERATIONS =
%w(SELECT INSERT UPDATE DELETE)
Instance Method Summary collapse
- #execute!(target) ⇒ Object
-
#initialize ⇒ QueryCounter
constructor
A new instance of QueryCounter.
- #queries ⇒ Object
- #query_count ⇒ Object
Constructor Details
#initialize ⇒ QueryCounter
Returns a new instance of QueryCounter.
5 6 7 |
# File 'lib/query_matchers/query_counter.rb', line 5 def initialize @events = [] end |
Instance Method Details
#execute!(target) ⇒ Object
9 10 11 |
# File 'lib/query_matchers/query_counter.rb', line 9 def execute!(target) ActiveSupport::Notifications.subscribed(subscriber, 'sql.active_record', &target) end |
#queries ⇒ Object
17 18 19 |
# File 'lib/query_matchers/query_counter.rb', line 17 def queries @events.map {|event| event.payload[:sql] } end |
#query_count ⇒ Object
13 14 15 |
# File 'lib/query_matchers/query_counter.rb', line 13 def query_count @events.size end |