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
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/xify.rb', line 12
def self.run
working_dir = "#{ENV['HOME']}/.xify"
Dir.mkdir working_dir rescue Errno::EEXIST
config_file = "#{working_dir}/config.yml"
files = []
while arg = ARGV.shift do
case arg
when '-c', '--config'
config_file = ARGV.shift
when '-v', '--verbose'
@verbose = true
else
files << arg
end
end
ARGV.unshift(*files)
debug "Loading config from #{config_file}"
config = YAML::load_file config_file
config.keys.each do |section|
type = section[0...-1]
config[section].map! do |handler|
next unless handler['enabled']
debug "Setting up #{handler['class']} as #{type}"
require "xify/#{type}/#{handler['class'].underscore}"
Object.const_get("Xify::#{type.capitalize}::#{handler['class']}").new handler
end.compact!
end
begin
config['inputs'].each do |i|
begin
i.updates do |u|
config['outputs'].each do |o|
begin
o.process u
rescue => e
error e
end
end
end
rescue => e
error e
end
end
Rufus::Scheduler.singleton.join
rescue Interrupt
$stderr.puts "\nExiting."
end
end
|