Class: SqlCapturer
- Inherits:
-
Object
- Object
- SqlCapturer
- Defined in:
- lib/has_metrics/sql_capturer.rb
Instance Attribute Summary collapse
-
#existing_logger ⇒ Object
Returns the value of attribute existing_logger.
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
- #capture(log) ⇒ Object (also: #debug)
- #debug? ⇒ Boolean
- #error(string) ⇒ Object
-
#initialize(existing_logger) ⇒ SqlCapturer
constructor
A new instance of SqlCapturer.
- #warn(message) ⇒ Object
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_logger ⇒ Object
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 |
#query ⇒ Object
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
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() existing_logger.try(:warn, ) end |