diff options
-rw-r--r-- | lib/chef/mixin/provides.rb | 4 | ||||
-rw-r--r-- | lib/chef/node_map.rb | 6 | ||||
-rw-r--r-- | lib/chef/resource.rb | 33 | ||||
-rw-r--r-- | lib/chef/resource/lwrp_base.rb | 3 | ||||
-rw-r--r-- | lib/chef/resource_resolver.rb | 8 |
5 files changed, 33 insertions, 21 deletions
diff --git a/lib/chef/mixin/provides.rb b/lib/chef/mixin/provides.rb index cb643b9cfc..5062ef24dd 100644 --- a/lib/chef/mixin/provides.rb +++ b/lib/chef/mixin/provides.rb @@ -23,8 +23,8 @@ class Chef node_map.set(short_name, true, opts, &block) end - def does_not_provide(short_name) - node_map.delete(short_name) + def provides_nothing + node_map.clear end # Check whether this resource provides the resource_name DSL for the given diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb index 5befdf25ec..17fda4a271 100644 --- a/lib/chef/node_map.rb +++ b/lib/chef/node_map.rb @@ -78,8 +78,10 @@ class Chef nil end - def delete(key) - @map.delete(key) + def clear + result = @map.keys + @map.clear + result end private diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 280da8734c..194a82b61b 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -978,16 +978,23 @@ class Chef super if subclass.dsl_name subclass.provides subclass.dsl_name.to_sym - subclass.instance_eval { @auto_provides = subclass.dsl_name.to_sym } + subclass.using_automatic_dsl = true end end + def self.using_automatic_dsl? + @using_automatic_dsl + end + + def self.using_automatic_dsl=(value) + @using_automatic_dsl = value + end + def self.provides(name, *args, &block) # If the user specifies provides, then we get rid of the auto-provided DSL # and let them specify what they want - if @auto_provides - @auto_provides = auto_provides = nil - does_not_provide(auto_provides) + if using_automatic_dsl? + provides_nothing end super @@ -995,18 +1002,16 @@ class Chef Chef::DSL::Resources.add_resource_dsl(name) end - def self.does_not_provide(name=nil) - name ||= dsl_name - if @auto_provides - @auto_provides = auto_provides = nil - does_not_provide(auto_provides) if name != auto_provides - end + def self.provides_nothing + @using_automatic_dsl = false - super + unprovided_names = super - # Get rid of the DSL if this was the only resource that used it - if !Chef::Resource.resource_matching_short_name(name) - Chef::DSL::Resources.remove_resource_dsl(name) + unprovided_names.each do |name| + resource = resource_matching_short_name(name) + if !resource || resource == self + Chef::DSL::Resources.remove_resource_dsl(name) + end end end diff --git a/lib/chef/resource/lwrp_base.rb b/lib/chef/resource/lwrp_base.rb index f702db5c96..c7a5f9d02e 100644 --- a/lib/chef/resource/lwrp_base.rb +++ b/lib/chef/resource/lwrp_base.rb @@ -28,6 +28,9 @@ class Chef # so attributes, default action, etc. can be defined with pleasing syntax. class LWRPBase < Resource + # Don't create DSL for l_w_r_p_base + provides_nothing + NULL_ARG = Object.new extend Chef::Mixin::ConvertToClassName diff --git a/lib/chef/resource_resolver.rb b/lib/chef/resource_resolver.rb index ac6b3d8839..e9aec11f62 100644 --- a/lib/chef/resource_resolver.rb +++ b/lib/chef/resource_resolver.rb @@ -105,10 +105,12 @@ class Chef # to the list of handlers for next time. resource_class = Chef::Resource.const_get(class_name) if resource_class <= Chef::Resource && !enabled_handlers.include?(resource_class) - Chef::Log.warn("Class #{resource_class} was created with Class.new and assigned directly to a constant (#{resource_class.name} = <class>) rather than being created directly (class #{resource_class.name} < <superclass>).") - Chef::Log.warn("This will no longer work in Chef 13: you can either declare your class directly (in any namespace), or specify 'provides #{resource.to_sym.inspect}' in the class definition.") - resource_class.provides resource.to_sym enabled_handlers << resource_class + if resource_class.using_automatic_dsl? + Chef::Log.warn("Class #{resource_class} was created with Class.new and assigned directly to a constant (#{resource_class.name} = <class>) rather than being created directly (class #{resource_class.name} < <superclass>).") + Chef::Log.warn("This will no longer work in Chef 13: you can either declare your class directly (in any namespace), or specify 'provides #{resource.to_sym.inspect}' in the class definition.") + resource_class.provides resource.to_sym + end end end end |