revamped some tests
[god.git] / lib / god / meddle.rb
blobca1f9cd762211294728ab50a539199e3beb6530d
1 module God
2   
3   class Meddle < Base
4     # drb
5     attr_accessor :server
6     
7     # api
8     attr_accessor :watches
9     
10     # Create a new instance that is ready for use by a configuration file
11     def initialize(options = {})
12       self.watches = []
13       self.server  = Server.new(self, options[:host], options[:port])
14     end
15       
16     # Instantiate a new, empty Watch object and pass it to the mandatory
17     # block. The attributes of the watch will be set by the configuration
18     # file.
19     def watch
20       w = Watch.new(self)
21       yield(w)
22       
23       # ensure the new watch has a unique name
24       unless @watches.select { |x| x.name == w.name }.empty?
25         abort "Duplicate Watch with name '#{w.name}'"
26       end
27       
28       # add to list of watches
29       @watches << w
30     end
31     
32     # Schedule all poll conditions and register all condition events
33     def monitor
34       @watches.each { |w| w.monitor }
35     end
36   end
37   
38 end