module PpSql::Rails5PpSqlExtraction

Private Instance Methods

colorize_payload_name(name, payload_name) click to toggle source

export from Rails 5 with for Rails 4.2+ versions

# File lib/pp_sql.rb, line 53
def colorize_payload_name(name, payload_name)
  if payload_name.blank? || payload_name == 'SQL' # SQL vs Model Load/Exists
    color(name, ActiveSupport::LogSubscriber::MAGENTA, true)
  else
    color(name, ActiveSupport::LogSubscriber::CYAN, true)
  end
end
sql_color(sql) click to toggle source
# File lib/pp_sql.rb, line 61
def sql_color(sql)
  case sql
  when /\A\s*rollback/mi                      then ActiveSupport::LogSubscriber::RED
  when /select .*for update/mi, /\A\s*lock/mi then ActiveSupport::LogSubscriber::WHITE
  when /\A\s*select/i                         then ActiveSupport::LogSubscriber::BLUE
  when /\A\s*insert/i                         then ActiveSupport::LogSubscriber::GREEN
  when /\A\s*update/i                         then ActiveSupport::LogSubscriber::YELLOW
  when /\A\s*delete/i                         then ActiveSupport::LogSubscriber::RED
  when /transaction\s*\Z/i                    then ActiveSupport::LogSubscriber::CYAN
  else                                             ActiveSupport::LogSubscriber::MAGENTA
  end
end