Class: QueryLimit::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/query_limit/analyzer.rb

Constant Summary collapse

MATCHER =
%r{\A(SELECT\s.*\sFROM\s.*\sWHERE\s)(.*)\z}

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#stackObject (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_np1Object



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