Class: N1Finder::Query
- Inherits:
-
Object
- Object
- N1Finder::Query
- Defined in:
- lib/n_1_finder/query.rb
Overview
Query representation
Constant Summary collapse
- ID =
Regular expression to find numeric ids in queries and in params
/(?<==\s)\d+/
- UUID =
Regular expression to find UUIDs in queries and in params
/(?<==\s)(['"])\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\1/
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
readonly
Returns the value of attribute backtrace.
-
#line ⇒ Object
readonly
Backtrace up to function where we cought this query.
-
#query ⇒ Object
readonly
Original query string combined with params.
Class Method Summary collapse
-
.query_with_params(query, params) ⇒ String
Combines query and its params to readable format.
Instance Method Summary collapse
-
#footprint ⇒ {query, line} => String
Generates query footprint Footprint consists of - query with masked ids - line of code where this query was executed.
-
#initialize(query, params, backtrace) ⇒ Query
constructor
A new instance of Query.
Constructor Details
#initialize(query, params, backtrace) ⇒ Query
Returns a new instance of Query.
20 21 22 23 |
# File 'lib/n_1_finder/query.rb', line 20 def initialize(query, params, backtrace) @query = self.class.query_with_params(query, params) @backtrace = backtrace end |
Instance Attribute Details
#backtrace ⇒ Object (readonly)
Returns the value of attribute backtrace.
15 16 17 |
# File 'lib/n_1_finder/query.rb', line 15 def backtrace @backtrace end |
#line ⇒ Object (readonly)
Backtrace up to function where we cought this query
15 |
# File 'lib/n_1_finder/query.rb', line 15 attr_reader :query, :backtrace |
#query ⇒ Object (readonly)
Original query string combined with params
15 16 17 |
# File 'lib/n_1_finder/query.rb', line 15 def query @query end |
Class Method Details
.query_with_params(query, params) ⇒ String
Combines query and its params to readable format
41 42 43 44 45 46 |
# File 'lib/n_1_finder/query.rb', line 41 def self.query_with_params(query, params) params.map do |key, value| value = "'#{value}'" if value.is_a?(String) "#{key} = #{value}" end.unshift(query).join(', ') end |