Sha256: 6ab567aeb29cc24db0e1177a320cda5538221da2399290580411c88d5c6788d3

Contents?: true

Size: 943 Bytes

Versions: 1

Compression:

Stored size: 943 Bytes

Contents

module God
  
  class Meddle < Base
    # drb
    attr_accessor :server
    
    # api
    attr_accessor :watches
    
    # Create a new instance that is ready for use by a configuration file
    def initialize(options = {})
      self.watches = []
      self.server  = Server.new(self, options[:host], options[:port])
    end
      
    # Instantiate a new, empty Watch object and pass it to the mandatory
    # block. The attributes of the watch will be set by the configuration
    # file.
    def watch
      w = Watch.new(self)
      yield(w)
      
      # ensure the new watch has a unique name
      unless @watches.select { |x| x.name == w.name }.empty?
        abort "Duplicate Watch with name '#{w.name}'"
      end
      
      # add to list of watches
      @watches << w
    end
    
    # Schedule all poll conditions and register all condition events
    def monitor
      @watches.each { |w| w.monitor }
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
god-0.2.0 lib/god/meddle.rb