Sha256: 03c5fb53ad3de98d6cfd0cbea0f553e1c8f8a0de5a187e71ea2b8e37fb51916d

Contents?: true

Size: 1.11 KB

Versions: 90

Compression:

Stored size: 1.11 KB

Contents

require 'chef/event_dispatch/base'

class Chef
  module EventDispatch

    # == EventDispatch::Dispatcher
    # The Dispatcher handles receiving event data from the sources
    # (Chef::Client, Resources and Providers, etc.) and publishing the data to
    # the registered subscribers.
    class Dispatcher < Base

      def initialize(*subscribers)
        @subscribers = subscribers
      end

      # Add a new subscriber to the list of registered subscribers
      def register(subscriber)
        @subscribers << subscriber
      end

      ####
      # All messages are unconditionally forwarded to all subscribers, so just
      # define the forwarding in one go:
      #

      # Define a method that will be forwarded to all 
      def self.def_forwarding_method(method_name)
        class_eval(<<-END_OF_METHOD, __FILE__, __LINE__)
          def #{method_name}(*args)
            @subscribers.each {|s| s.#{method_name}(*args)}
          end
        END_OF_METHOD
      end

      (Base.instance_methods - Object.instance_methods).each do |method_name|
        def_forwarding_method(method_name)
      end

    end
  end
end

Version data entries

90 entries across 90 versions & 2 rubygems

Version Path
chef-10.34.6-x86-mingw32 lib/chef/event_dispatch/dispatcher.rb
chef-10.34.6 lib/chef/event_dispatch/dispatcher.rb
chef-10.34.4 lib/chef/event_dispatch/dispatcher.rb
chef-10.34.4-x86-mingw32 lib/chef/event_dispatch/dispatcher.rb
chef-10.34.2-x86-mingw32 lib/chef/event_dispatch/dispatcher.rb
chef-10.34.2 lib/chef/event_dispatch/dispatcher.rb
chef-10.34.0-x86-mingw32 lib/chef/event_dispatch/dispatcher.rb
chef-10.34.0 lib/chef/event_dispatch/dispatcher.rb
chef-10.32.2-x86-mingw32 lib/chef/event_dispatch/dispatcher.rb
chef-10.32.2 lib/chef/event_dispatch/dispatcher.rb
chef-10.32.0.rc.0 lib/chef/event_dispatch/dispatcher.rb
chef-10.32.0.rc.0-x86-mingw32 lib/chef/event_dispatch/dispatcher.rb
chef-10.30.4 lib/chef/event_dispatch/dispatcher.rb
chef-10.30.4-x86-mingw32 lib/chef/event_dispatch/dispatcher.rb
chef-10.30.2 lib/chef/event_dispatch/dispatcher.rb
chef-10.30.2-x86-mingw32 lib/chef/event_dispatch/dispatcher.rb
chef-10.30.2.rc.0-x86-mingw32 lib/chef/event_dispatch/dispatcher.rb
chef-10.30.2.rc.0 lib/chef/event_dispatch/dispatcher.rb
chef-10.30.0.rc.2-x86-mingw32 lib/chef/event_dispatch/dispatcher.rb
chef-10.30.0.rc.2 lib/chef/event_dispatch/dispatcher.rb