Module: Fluke

Defined in:
lib/fluke.rb,
lib/fluke/cli.rb,
lib/fluke/result.rb,
lib/fluke/watcher.rb,
lib/fluke/monkey_patch.rb

Defined Under Namespace

Modules: Delays Classes: CLI, Result, Watcher

Constant Summary collapse

VERSION =
'0.0.4'
ROOT =
Dir.new(File.expand_path(File.dirname(__FILE__) + "/../"))
DEFAULT_CONF_PATH =
"~/.fluke.yml"
@@verbose =
false
@@watchers =
{}
@@mutex =
{ :s3 => Mutex.new }

Class Method Summary collapse

Class Method Details

.confObject



32
33
34
# File 'lib/fluke.rb', line 32

def self.conf
  @@conf.dup
end

.configure!(opts = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/fluke.rb', line 55

def self.configure!(opts = {})
  p = {
    :conf_path => File.expand_path(DEFAULT_CONF_PATH),
    :stdout => STDOUT,
    :stderr => STDERR,
    :log_here => :stderr
  }
  p.merge! opts
  @@log_here = p[p[:log_here]] || p[:stderr]

  begin
    @@conf = YAML::load(File.open(p[:conf_path]))
    if !@@conf[:proxy].nil?
      @@conf[:s3][:connection][:proxy] = @@conf[:proxy]
      @@conf[:proxy_string] = "http://#{@@conf[:proxy][:host]}:#{@@conf[:proxy][:port]}"
    end
    if verbose?
      DataMapper::Logger.new(@@log_here, :debug)
    end
    DataMapper.setup(:default, @@conf[:db])
    AWS::S3::Base.establish_connection!(@@conf[:s3][:connection])
    Result::Body.set_current_bucket_to @@conf[:s3][:bucket][:result]
  rescue => e
    STDERR.puts e.inspect
    return false
  end
  return true
end

.logObject



40
41
42
43
# File 'lib/fluke.rb', line 40

def self.log
  return unless verbose? and block_given?
  @@log_here.puts yield
end

.mutexObject



36
37
38
# File 'lib/fluke.rb', line 36

def self.mutex
  @@mutex
end

.run!Object



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/fluke.rb', line 84

def self.run!
  watchers.each do |n,watcher|
    watcher.thread = Thread.new do
      while true
        watcher.run
        watcher.wait
      end
    end
  end

  sleep while true
end

.verbose=(v = false) ⇒ Object



24
25
26
# File 'lib/fluke.rb', line 24

def self.verbose=(v = false)
  @@verbose = v ? true : false
end

.verbose?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/fluke.rb', line 20

def self.verbose?
  @@verbose
end

.watch(watcher, &init) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/fluke.rb', line 45

def self.watch(watcher, &init)
  unless watcher.is_a?(Watcher)
    watcher = Watcher.first(:name => watcher.to_s)
  end
  watchers[watcher.name] = watcher
  if init
    watcher.instance_eval &init
  end
end

.watchersObject



28
29
30
# File 'lib/fluke.rb', line 28

def self.watchers
  @@watchers
end