Sha256: 9ed692c8fa2bed7cd6415f36bab80d29978eb57ff7e0c4c85fc503448e2858b3

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Emittance
  ##
  # Can watch for events that propagate through the system.
  #
  module Watcher
    # Watch for an event, identified by its class' identifier. If a callback method is provided, then it will call that
    # method on the caller of +watch+ when the event happens. Otherwise, it will run the callback block.
    #
    # @param identifier [Symbol] the event's identifier
    # @param callback_method [Symbol] one option for adding a callback--the method on the object to call when the
    #   event fires
    # @param callback [Block] the other option for adding a callback--the block you wish to be executed when the event
    #   fires
    # @return [Proc] the block that will run when the event fires
    def watch(identifier, callback_method = nil, &callback)
      if callback_method
        Emittance::Dispatcher.register_method_call identifier, self, callback_method
      else
        Emittance::Dispatcher.register identifier, &callback
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
emittance-0.0.3 lib/emittance/watcher.rb