Module: Xify

Defined in:
lib/xify.rb,
lib/xify/event.rb

Defined Under Namespace

Classes: Event

Class Method Summary collapse

Class Method Details

.debug(str) ⇒ Object



64
65
66
# File 'lib/xify.rb', line 64

def self.debug(str)
  puts str if @verbose
end

.error(e) ⇒ Object



68
69
70
71
72
# File 'lib/xify.rb', line 68

def self.error(e)
  return $stderr.puts e.message unless @verbose

  $stderr.puts "#{e.backtrace.first}: #{e.message} (#{e.class})", e.backtrace.drop(1).map{|s| "\t#{s}"}
end

.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
54
55
56
57
58
59
60
61
62
# File 'lib/xify.rb', line 9

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