Module: Polyrun::SpecQuality::SqlCounter
- Defined in:
- lib/polyrun/spec_quality/sql_counter.rb
Overview
Optional per-example SQL query counting via ActiveSupport::Notifications.
Class Method Summary collapse
Class Method Details
.install! ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/polyrun/spec_quality/sql_counter.rb', line 6 def install! return false unless notifications_available? return true if @installed @installed = true @subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args| next unless Polyrun::SpecQuality.recording? event = ActiveSupport::Notifications::Event.new(*args) Polyrun::SpecQuality.record_sql!(event.payload[:sql].to_s) end true end |
.notifications_available? ⇒ Boolean
28 29 30 |
# File 'lib/polyrun/spec_quality/sql_counter.rb', line 28 def notifications_available? defined?(ActiveSupport::Notifications) end |
.uninstall! ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/polyrun/spec_quality/sql_counter.rb', line 20 def uninstall! return unless @installed && @subscriber ActiveSupport::Notifications.unsubscribe(@subscriber) @subscriber = nil @installed = false end |