Sha256: e17e38c3c8ab3b6baa1553e747e92a496369861848aae9c2924364d6ce53cff4

Contents?: true

Size: 937 Bytes

Versions: 69

Compression:

Stored size: 937 Bytes

Contents

module God
  
  class Trigger
    
    class << self
      attr_accessor :triggers # {task.name => condition}
    end
    
    # init
    self.triggers = {}
    @mutex = Mutex.new
    
    def self.register(condition)
      @mutex.synchronize do
        self.triggers[condition.watch.name] ||= []
        self.triggers[condition.watch.name] << condition
      end
    end
    
    def self.deregister(condition)
      @mutex.synchronize do
        self.triggers[condition.watch.name].delete(condition)
        self.triggers.delete(condition.watch.name) if self.triggers[condition.watch.name].empty?
      end
    end
    
    def self.broadcast(task, message, payload)
      return unless self.triggers[task.name]
      
      @mutex.synchronize do
        self.triggers[task.name].each do |t|
          t.process(message, payload)
        end
      end
    end
    
    def self.reset
      self.triggers.clear
    end
    
  end
  
end

Version data entries

69 entries across 69 versions & 21 rubygems

Version Path
dguettler-god-0.7.13.2 lib/god/trigger.rb
dguettler-god-0.7.13.3 lib/god/trigger.rb
dosire-god-0.7.10 lib/god/trigger.rb
dosire-god-0.7.12 lib/god/trigger.rb
dosire-god-0.7.9 lib/god/trigger.rb
dunedain289-god-0.7.12.1 lib/god/trigger.rb
dustin-god-0.7.7.1 lib/god/trigger.rb
eric-god-0.7.10 lib/god/trigger.rb
eric-god-0.7.11 lib/god/trigger.rb
eric-god-0.7.12 lib/god/trigger.rb
eric-god-0.7.14 lib/god/trigger.rb
eric-god-0.7.7 lib/god/trigger.rb
fotonauts-god-0.7.10 lib/god/trigger.rb
fotonauts-god-0.7.12 lib/god/trigger.rb
gohanlonllc-god-0.7.9 lib/god/trigger.rb
gordoncww-god-0.7.11.1 lib/god/trigger.rb
jreynolds-god-0.7.13 lib/god/trigger.rb
jwilkins-god-0.7.9 lib/god/trigger.rb
mathieuravaux-god-0.7.11 lib/god/trigger.rb
mojombo-god-0.7.10 lib/god/trigger.rb