blob: 9f43f143112104bf46fc0b66bbb30314a466bd26 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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)
define_method(method_name) do |*args|
@subscribers.each { |s| s.send(method_name, *args) }
end
end
(Base.instance_methods - Object.instance_methods).each do |method_name|
def_forwarding_method(method_name)
end
end
end
end
|