Class: See::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/see/runner.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runObject



5
6
7
# File 'lib/see/runner.rb', line 5

def self.run
  Runner.new.run
end

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
# File 'lib/see/runner.rb', line 9

def run
  #
  # Whole thing happens in two major steps:
  #   1. load ./see.yml
  #     (fail if it doesn't exist)
  #
  #   2. provide information from each configured plugin
  #     (provide content at the top and no content at the bottom)
  #
  config_path = "#{Dir.pwd}/see.yml"
  begin
    config = YAML.load_file(config_path)
  rescue
    puts "No configuration file found (tried #{config_path})".yellow
    puts '  (if the file exists it may be malformed)'
    exit 1
  end

  progress = Thread.new do
    print "Pulling data from #{config.length} source#{config.length == 1 ? '' : 's'}"
    loop do
      sleep 0.25
      print '.'
    end
  end

  threads = []
  config.each do |cfg|
    threads << Thread.new do
      begin
        Thread.current[:lines] = [See::Plugins.run_plugin(cfg[0], config)]
      rescue => error
        Thread.current[:lines] = ["Error running plugin: #{cfg[0]}".red]
        Thread.current[:lines] << "  #{error}".light_red
      end
    end
  end

  lines = threads.map { |t| t.join[:lines].flatten }
  progress.kill

  puts
  lines.sort_by { |l| l[0] }.each { |l| puts l }
  puts
end