diff options
author | John Keiser <john@johnkeiser.com> | 2015-05-28 13:05:46 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-05-28 13:27:44 -0700 |
commit | 81eaaa29cc175420e0ed6013cd2772b8941b65e7 (patch) | |
tree | f1d28b88f7c868c9bec112679a233150e7c9525d /lib/chef | |
parent | f6ae5a3815cbcff6dbe0bbc66276e6929838ff9c (diff) | |
download | chef-81eaaa29cc175420e0ed6013cd2772b8941b65e7.tar.gz |
Move notification methods back to Client
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/client.rb | 85 | ||||
-rw-r--r-- | lib/chef/client/notification_registry.rb | 105 |
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(¬ification_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(¬ification_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(¬ification_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(¬ification_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(¬ification_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(¬ification_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 |