Class: QueryLimit::Analyzer
- Inherits:
-
Object
- Object
- QueryLimit::Analyzer
- Defined in:
- lib/query_limit/analyzer.rb
Constant Summary collapse
- MATCHER =
%r{\A(SELECT\s.*\sFROM\s.*\sWHERE\s)(.*)\z}
Instance Attribute Summary collapse
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #analyze_np1 ⇒ Object
-
#initialize(stack) ⇒ Analyzer
constructor
A new instance of Analyzer.
Constructor Details
#initialize(stack) ⇒ Analyzer
Returns a new instance of Analyzer.
5 6 7 |
# File 'lib/query_limit/analyzer.rb', line 5 def initialize(stack) @stack = stack end |
Instance Attribute Details
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
9 10 11 |
# File 'lib/query_limit/analyzer.rb', line 9 def stack @stack end |
Instance Method Details
#analyze_np1 ⇒ Object
11 12 13 14 15 16 |
# File 'lib/query_limit/analyzer.rb', line 11 def analyze_np1 grp = stack.group_by { |entry| entry.sql.match(MATCHER)&.captures&.at(1) } diff = grp.values.find { |entries| entries.size > 1 } tell_the_story(diff.first.sql, diff.first.stacktrace) if diff end |