summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/client.rb85
-rw-r--r--lib/chef/client/notification_registry.rb105
2 files changed, 83 insertions, 107 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index 94aae15f03..b63671bd59 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -50,7 +50,6 @@ require 'chef/run_lock'
require 'chef/policy_builder'
require 'chef/request_id'
require 'chef/platform/rebooter'
-require 'chef/client/notification_registry'
require 'chef/mixin/deprecation'
require 'ohai'
require 'rbconfig'
@@ -62,7 +61,6 @@ class Chef
class Client
include Chef::Mixin::PathSanity
- extend NotificationRegistry
extend Chef::Mixin::Deprecation
#
@@ -766,6 +764,89 @@ class Chef
end
end
+ # Notification registration
+ class<<self
+ #
+ # Add a listener for the 'client run started' event.
+ #
+ # @param notification_block The callback (takes |run_status| parameter).
+ # @yieldparam [Chef::RunStatus] run_status The run status.
+ #
+ def when_run_starts(&notification_block)
+ run_start_notifications << notification_block
+ end
+
+ #
+ # Add a listener for the 'client run success' event.
+ #
+ # @param notification_block The callback (takes |run_status| parameter).
+ # @yieldparam [Chef::RunStatus] run_status The run status.
+ #
+ def when_run_completes_successfully(&notification_block)
+ run_completed_successfully_notifications << notification_block
+ end
+
+ #
+ # Add a listener for the 'client run failed' event.
+ #
+ # @param notification_block The callback (takes |run_status| parameter).
+ # @yieldparam [Chef::RunStatus] run_status The run status.
+ #
+ def when_run_fails(&notification_block)
+ run_failed_notifications << notification_block
+ end
+
+ #
+ # Clears all listeners for client run status events.
+ #
+ # Primarily for testing purposes.
+ #
+ # @api private
+ #
+ def clear_notifications
+ @run_start_notifications = nil
+ @run_completed_successfully_notifications = nil
+ @run_failed_notifications = nil
+ end
+
+ #
+ # TODO These seem protected to me.
+ #
+
+ #
+ # Listeners to be run when the client run starts.
+ #
+ # @return [Array<Proc>]
+ #
+ # @api private
+ #
+ def run_start_notifications
+ @run_start_notifications ||= []
+ end
+
+ #
+ # Listeners to be run when the client run completes successfully.
+ #
+ # @return [Array<Proc>]
+ #
+ # @api private
+ #
+ def run_completed_successfully_notifications
+ @run_completed_successfully_notifications ||= []
+ end
+
+ #
+ # Listeners to be run when the client run fails.
+ #
+ # @return [Array<Proc>]
+ #
+ # @api private
+ #
+ def run_failed_notifications
+ @run_failed_notifications ||= []
+ end
+ end
+
#
# IO stream that will be used as 'STDOUT' for formatters. Formatters are
# configured during `initialize`, so this provides a convenience for
diff --git a/lib/chef/client/notification_registry.rb b/lib/chef/client/notification_registry.rb
deleted file mode 100644
index 78d0b1f687..0000000000
--- a/lib/chef/client/notification_registry.rb
+++ /dev/null
@@ -1,105 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Christopher Walters (<cw@opscode.com>)
-# Author:: Christopher Brown (<cb@opscode.com>)
-# Author:: Tim Hinderliter (<tim@opscode.com>)
-# Copyright:: Copyright (c) 2008-2011 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-class Chef
- class Client
- module NotificationRegistry
- #
- # Add a listener for the 'client run started' event.
- #
- # @param notification_block The callback (takes |run_status| parameter).
- # @yieldparam [Chef::RunStatus] run_status The run status.
- #
- def when_run_starts(&notification_block)
- run_start_notifications << notification_block
- end
-
- #
- # Add a listener for the 'client run success' event.
- #
- # @param notification_block The callback (takes |run_status| parameter).
- # @yieldparam [Chef::RunStatus] run_status The run status.
- #
- def when_run_completes_successfully(&notification_block)
- run_completed_successfully_notifications << notification_block
- end
-
- #
- # Add a listener for the 'client run failed' event.
- #
- # @param notification_block The callback (takes |run_status| parameter).
- # @yieldparam [Chef::RunStatus] run_status The run status.
- #
- def when_run_fails(&notification_block)
- run_failed_notifications << notification_block
- end
-
- #
- # Clears all listeners for client run status events.
- #
- # Primarily for testing purposes.
- #
- # @api private
- #
- def clear_notifications
- @run_start_notifications = nil
- @run_completed_successfully_notifications = nil
- @run_failed_notifications = nil
- end
-
- #
- # TODO These seem protected to me.
- #
-
- #
- # Listeners to be run when the client run starts.
- #
- # @return [Array<Proc>]
- #
- # @api private
- #
- def run_start_notifications
- @run_start_notifications ||= []
- end
-
- #
- # Listeners to be run when the client run completes successfully.
- #
- # @return [Array<Proc>]
- #
- # @api private
- #
- def run_completed_successfully_notifications
- @run_completed_successfully_notifications ||= []
- end
-
- #
- # Listeners to be run when the client run fails.
- #
- # @return [Array<Proc>]
- #
- # @api private
- #
- def run_failed_notifications
- @run_failed_notifications ||= []
- end
- end
- end
-end