Method: Toolbus#scan

Defined in:
lib/toolbus.rb

#scanObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/toolbus.rb', line 27

def scan
  statuses = []
  progress = 0.0
  @features.map { |feature| feature.default = 0 } # helps measure progress
  num_steps = scanning_plan.inject(0) { |total, (file, blueprints)| total + blueprints.length }

  scanning_plan.each_with_index do |(file, search_for), file_index|
    statuses << "Scanning #{file}"
    search_for.each do |search_for|
      id = search_for.keys.first
      blueprint = search_for.values.first

      progress += 1
      begin
        match = SyntaxTree.new(file).include?(SyntaxTree.new(blueprint))
      rescue Parser::SyntaxError
        statuses << "Syntax Error: #{file}"
        next
      end

      if match
        feature = @features.find { |feature| feature['id'] == id }
        feature['count'] += 1
        statuses << "POST /completions: repo_url: #{repo_url}, feature_id: #{id}, filename: #{file}, first_line: #{match[:first_line]}, last_line: #{match[:last_line]}, commit: #{head_sha}"
      end

      percent_complete = (progress / num_steps) * 100
      ConsoleManager.repaint([
        ProgressBarView.new(percent_complete),
        TableView.new(features_found),
        StatusBoxView.new(statuses),
        "Found #{num_completions} total completions across #{num_features_completed}/#{@features.count} features across #{file_index}/#{scanning_plan.count} files!"
      ])
      sleep SCAN_TIME_SECONDS / num_steps
    end
  end
end