class Chef::Resource::ChefHandler
Public Instance Methods
collect_args(resource_args = [])
click to toggle source
# File lib/chef/resource/chef_handler.rb, line 120 def collect_args(resource_args = []) if resource_args.is_a? Array resource_args else [resource_args] end end
get_class(class_full_name)
click to toggle source
Walks down the namespace heirarchy to return the class object for the given class name. If the class is not available, NameError is thrown.
@param class_full_name [String] full class name such as 'Chef::Handler::Foo' or 'MyHandler'. @return [Array] parent class and child class.
# File lib/chef/resource/chef_handler.rb, line 108 def get_class(class_full_name) ancestors = class_full_name.split("::") class_name = ancestors.pop # We need to search the ancestors only for the first/uppermost namespace of the class, so we # need to enable the #const_get inherit paramenter only when we are searching in Kernel scope # (see COOK-4117). parent = ancestors.inject(Kernel) { |scope, const_name| scope.const_get(const_name, scope === Kernel) } child = parent.const_get(class_name, parent === Kernel) [parent, child] end
register_handler(handler_type, handler)
click to toggle source
Registers a handler in Chef::Config.
@param handler_type [Symbol] such as :report or :exception. @param handler [Chef::Handler] handler to register.
# File lib/chef/resource/chef_handler.rb, line 84 def register_handler(handler_type, handler) Chef::Log.info("Enabling #{handler.class.name} as a #{handler_type} handler.") Chef::Config.send("#{handler_type}_handlers") << handler end
unregister_handler(handler_type, class_full_name)
click to toggle source
Removes all handlers that match the given class name in Chef::Config.
@param handler_type [Symbol] such as :report or :exception. @param class_full_name [String] such as 'Chef::Handler::ErrorReport'.
# File lib/chef/resource/chef_handler.rb, line 93 def unregister_handler(handler_type, class_full_name) Chef::Config.send("#{handler_type}_handlers").delete_if do |v| # avoid a bit of log spam if v.class.name == class_full_name Chef::Log.info("Disabling #{class_full_name} as a #{handler_type} handler.") true end end end