class Chef::Resource::ChefHandler
Public Instance Methods
Source
# File lib/chef/resource/chef_handler.rb, line 268 def collect_args(resource_args = []) if resource_args.is_a? Array resource_args else [resource_args] end end
Source
# File lib/chef/resource/chef_handler.rb, line 256 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 parameter 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
Walks down the namespace hierarchy 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.
Source
# File lib/chef/resource/chef_handler.rb, line 229 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
Registers a handler in Chef::Config
.
@param handler_type [Symbol] such as :report or :exception. @param handler [Chef::Handler] handler to register.
Source
# File lib/chef/resource/chef_handler.rb, line 240 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
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’.
@return [void]