Sha256: adb2f68b2f3bc77f83bd64c3e851f6c9f56cc4ca3ca0c74411ea1dccd105dcbd

Contents?: true

Size: 900 Bytes

Versions: 12

Compression:

Stored size: 900 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

12 entries across 12 versions & 3 rubygems

Version Path
resurrected_god-0.14.0 lib/god/trigger.rb
mcproc-2016.2.20 lib/god/trigger.rb
god-0.13.7 lib/god/trigger.rb
god-0.13.6 lib/god/trigger.rb
god-0.13.5 lib/god/trigger.rb
god-0.13.4 lib/god/trigger.rb
god-0.13.3 lib/god/trigger.rb
god-0.13.2 lib/god/trigger.rb
god-0.13.1 lib/god/trigger.rb
god-0.13.0 lib/god/trigger.rb
god-0.12.1 lib/god/trigger.rb
god-0.12.0 lib/god/trigger.rb