repo.or.cz
/
god.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
history
|
raw
|
HEAD
Initial commit
[god.git]
/
pkg
/
god-0.1.0
/
lib
/
god.rb
blob
42daaf9f8af58d50636fbc42f4615e981b216f37
1
$:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
2
3
require 'god/condition'
4
require 'god/watch'
5
require 'god/conditions/process_not_running'
6
7
module God
8
VERSION = '0.1.0'
9
10
class AbstractMethodNotOverriddenError < StandardError
11
end
12
13
def self.meddle
14
m = Meddle.new
15
yield m
16
m.monitor
17
end
18
19
class Meddle
20
attr_accessor :interval
21
22
def initialize
23
@watches = []
24
end
25
26
def settings
27
28
end
29
30
def watch
31
w = Watch.new
32
yield(w)
33
@watches << w
34
end
35
36
def monitor
37
threads = []
38
@watches.each do |w|
39
t = Thread.new do
40
while true do
41
if a = w.run
42
w.action(a)
43
end
44
sleep self.interval
45
end
46
end
47
t.join
48
threads << t
49
end
50
end
51
end
52
end