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)
- RAILS5_INFORMATION_SCHEMA_REGEX =
/^\s*SELECT.+FROM information_schema\./m
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.
6 7 8 |
# File 'lib/query_matchers/query_counter.rb', line 6 def initialize @events = [] end |
Instance Method Details
#execute!(target) ⇒ Object
10 11 12 |
# File 'lib/query_matchers/query_counter.rb', line 10 def execute!(target) ActiveSupport::Notifications.subscribed(subscriber, 'sql.active_record', &target) end |
#queries ⇒ Object
18 19 20 |
# File 'lib/query_matchers/query_counter.rb', line 18 def queries @events.map {|event| event.payload[:sql] } end |
#query_count ⇒ Object
14 15 16 |
# File 'lib/query_matchers/query_counter.rb', line 14 def query_count @events.size end |