Class: ROM::SQL::RailsLogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/rom/sql/extensions/rails_log_subscriber.rb

Instance Method Summary collapse

Instance Method Details

#odd?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/rom/sql/extensions/rails_log_subscriber.rb', line 29

def odd?
  @odd_or_even = !odd_or_even
end

#sql(event) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rom/sql/extensions/rails_log_subscriber.rb', line 8

def sql(event)
  return unless logger.debug?

  payload = event.payload

  name = format('%s (%.1fms)', payload[:name], event.duration)
  sql  = payload[:sql].squeeze(' ')
  binds = payload[:binds].to_a.inspect if payload[:binds]

  if odd?
    name = color(name, :cyan, true)
    sql  = color(sql, nil, true)
  else
    name = color(name, :magenta, true)
  end

  debug "  #{name}  #{sql}  #{binds}"
end