Class: Querly::Analyzer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:) ⇒ Analyzer



6
7
8
9
# File 'lib/querly/analyzer.rb', line 6

def initialize(config:)
  @config = config
  @scripts = []
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/querly/analyzer.rb', line 3

def config
  @config
end

#scriptsObject (readonly)

Returns the value of attribute scripts.



4
5
6
# File 'lib/querly/analyzer.rb', line 4

def scripts
  @scripts
end

Instance Method Details

#find(pattern) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/querly/analyzer.rb', line 27

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

#runObject

yields(script, rule, node_pair)



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/querly/analyzer.rb', line 14

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.patterns.any? {|pattern| test_pair(node_pair, pattern) }
          yield script, rule, node_pair
        end
      end
    end
  end
end

#test_pair(node_pair, pattern) ⇒ Object



37
38
39
# File 'lib/querly/analyzer.rb', line 37

def test_pair(node_pair, pattern)
  pattern.expr =~ node_pair && pattern.test_kind(node_pair)
end