Module: Chef::RemoveExistingLWRP
- Included in:
- Provider::LWRPBase, Chef::Resource::LWRPBase
- Defined in:
- lib/chefspec/extensions/chef/lwrp_base.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#build_from_file_with_removal(cookbook_name, filename, run_context) ⇒ Chef::Provider
Override Opscode provider to remove any existing LWRPs to suppress constant re-definition warnings.
-
#remove_existing_lwrp(class_name) ⇒ Object
Remove any existing Chef provider or resource with the specified name.
Class Method Details
.extended(klass) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/chefspec/extensions/chef/lwrp_base.rb', line 4 def self.extended(klass) class << klass alias_method :build_from_file_without_removal, :build_from_file alias_method :build_from_file, :build_from_file_with_removal end end |
Instance Method Details
#build_from_file_with_removal(cookbook_name, filename, run_context) ⇒ Chef::Provider
Override Opscode provider to remove any existing LWRPs to suppress constant re-definition warnings.
24 25 26 27 28 29 30 |
# File 'lib/chefspec/extensions/chef/lwrp_base.rb', line 24 def build_from_file_with_removal(cookbook_name, filename, run_context) provider_name = filename_to_qualified_string(cookbook_name, filename) class_name = convert_to_class_name(provider_name) remove_existing_lwrp(class_name) build_from_file_without_removal(cookbook_name, filename, run_context) end |
#remove_existing_lwrp(class_name) ⇒ Object
Remove any existing Chef provider or resource with the specified name.
38 39 40 41 42 43 44 45 |
# File 'lib/chefspec/extensions/chef/lwrp_base.rb', line 38 def remove_existing_lwrp(class_name) [self, superclass].each do |resource_holder| look_in_parents = false if resource_holder.const_defined?(class_name, look_in_parents) resource_holder.send(:remove_const, class_name) end end end |