Class: NotificationTracer::RailsSql
- Inherits:
-
Object
- Object
- NotificationTracer::RailsSql
- Defined in:
- lib/notification_tracer/rails_sql.rb
Instance Attribute Summary collapse
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
Instance Method Summary collapse
- #call(stack:, payload:, duration:, event_id:, event_name:) ⇒ Object
-
#initialize(matcher:, logger:, formatter:, lines: nil, silence_rails_code: true) ⇒ RailsSql
constructor
A new instance of RailsSql.
- #pause ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(matcher:, logger:, formatter:, lines: nil, silence_rails_code: true) ⇒ RailsSql
Returns a new instance of RailsSql.
5 6 7 8 9 10 11 12 13 |
# File 'lib/notification_tracer/rails_sql.rb', line 5 def initialize(matcher:, logger:, formatter:, lines: nil, silence_rails_code: true) @enabled = false @lines = Integer(lines) if lines @matcher = matcher @logger = logger @formatter = formatter @subscriber = make_subscriber(silence_rails_code: silence_rails_code) end |
Instance Attribute Details
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
3 4 5 |
# File 'lib/notification_tracer/rails_sql.rb', line 3 def enabled @enabled end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
3 4 5 |
# File 'lib/notification_tracer/rails_sql.rb', line 3 def lines @lines end |
Instance Method Details
#call(stack:, payload:, duration:, event_id:, event_name:) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/notification_tracer/rails_sql.rb', line 32 def call(stack:, payload:, duration:, event_id:, event_name:) return unless enabled return unless matches?(payload) stack = stack[0..(lines-1)] if lines stack = stack.select{ |l| l && !l.empty? } return if stack.empty? data = formatter.call(stack: stack, sql: payload[:sql], duration: duration, uuid: event_id) logger.call(data) if data end |
#pause ⇒ Object
21 22 23 24 |
# File 'lib/notification_tracer/rails_sql.rb', line 21 def pause @enabled = false self end |
#start ⇒ Object
15 16 17 18 19 |
# File 'lib/notification_tracer/rails_sql.rb', line 15 def start @enabled = true subscriber.subscribe self end |
#stop ⇒ Object
26 27 28 29 30 |
# File 'lib/notification_tracer/rails_sql.rb', line 26 def stop @enabled = false subscriber.unsubscribe self end |