Class: SqlCapturer

Inherits:
Object
  • Object
show all
Defined in:
lib/has_metrics/sql_capturer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(existing_logger) ⇒ SqlCapturer

Returns a new instance of SqlCapturer.



4
5
6
7
8
# File 'lib/has_metrics/sql_capturer.rb', line 4

def initialize(existing_logger)
  self.query = []
  self.existing_logger = existing_logger
  self
end

Instance Attribute Details

#existing_loggerObject

Returns the value of attribute existing_logger.



2
3
4
# File 'lib/has_metrics/sql_capturer.rb', line 2

def existing_logger
  @existing_logger
end

#queryObject

Returns the value of attribute query.



2
3
4
# File 'lib/has_metrics/sql_capturer.rb', line 2

def query
  @query
end

Instance Method Details

#capture(log) ⇒ Object Also known as: debug



22
23
24
25
26
27
# File 'lib/has_metrics/sql_capturer.rb', line 22

def capture(log)
  if select_statement = log.index("SELECT")
    self.query << log[select_statement..-1].gsub(/\e\[(\d+)m/, '')
  end
  existing_logger.debug(log) if existing_logger
end

#debug?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/has_metrics/sql_capturer.rb', line 14

def debug?
  true
end

#error(string) ⇒ Object



10
11
12
# File 'lib/has_metrics/sql_capturer.rb', line 10

def error(string)
  raise string
end

#warn(message) ⇒ Object



18
19
20
# File 'lib/has_metrics/sql_capturer.rb', line 18

def warn(message)
  existing_logger.try(:warn, message)
end