class Querly::Analyzer

Attributes

config[R]
rule[R]
scripts[R]

Public Class Methods

new(config:, rule:) click to toggle source
# File lib/querly/analyzer.rb, line 7
def initialize(config:, rule:)
  @config = config
  @scripts = []
  @rule = rule
end

Public Instance Methods

find(pattern) { |script, node_pair| ... } click to toggle source
# File lib/querly/analyzer.rb, line 31
def find(pattern)
  scripts.each do |script|
    script.root_pair.each_subpair do |node_pair|
      if test_pair(node_pair, pattern)
        yield script, node_pair
      end
    end
  end
end
run() { |script, rule, node_pair| ... } click to toggle source

yields(script, rule, node_pair)

# File lib/querly/analyzer.rb, line 16
def run
  scripts.each do |script|
    rules = config.rules_for_path(script.path)
    script.root_pair.each_subpair do |node_pair|
      rules.each do |rule|
        if rule.match?(identifier: self.rule)
          if rule.patterns.any? {|pattern| test_pair(node_pair, pattern) }
            yield script, rule, node_pair
          end
        end
      end
    end
  end
end
test_pair(node_pair, pattern) click to toggle source
# File lib/querly/analyzer.rb, line 41
def test_pair(node_pair, pattern)
  pattern.expr =~ node_pair && pattern.test_kind(node_pair)
end