diff options
author | John Keiser <john@johnkeiser.com> | 2015-04-19 09:45:45 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-05-13 13:42:32 -0700 |
commit | bf45150b190afa90a69c4317b0a89c4f8ebd20fa (patch) | |
tree | d07989e3e0eefc678da0112f2e7426227ad76343 | |
parent | a6d5241a96a7882166af849f529b2a2b8bab5ab4 (diff) | |
download | chef-bf45150b190afa90a69c4317b0a89c4f8ebd20fa.tar.gz |
Make explicit "provides" override automatic
-rw-r--r-- | lib/chef/dsl/resources.rb | 3 | ||||
-rw-r--r-- | lib/chef/mixin/provides.rb | 4 | ||||
-rw-r--r-- | lib/chef/node_map.rb | 4 | ||||
-rw-r--r-- | lib/chef/resource.rb | 24 |
4 files changed, 35 insertions, 0 deletions
diff --git a/lib/chef/dsl/resources.rb b/lib/chef/dsl/resources.rb index dfa0788879..482b14e3aa 100644 --- a/lib/chef/dsl/resources.rb +++ b/lib/chef/dsl/resources.rb @@ -14,6 +14,9 @@ class Chef end EOM end + def self.remove_resource_dsl(dsl_name) + remove_method dsl_name if method_defined?(dsl_name) + end end end end diff --git a/lib/chef/mixin/provides.rb b/lib/chef/mixin/provides.rb index d71097ca4b..cb643b9cfc 100644 --- a/lib/chef/mixin/provides.rb +++ b/lib/chef/mixin/provides.rb @@ -23,6 +23,10 @@ class Chef node_map.set(short_name, true, opts, &block) end + def does_not_provide(short_name) + node_map.delete(short_name) + end + # Check whether this resource provides the resource_name DSL for the given # node def provides?(node, resource_name) diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb index 2ca6d9ba17..5befdf25ec 100644 --- a/lib/chef/node_map.rb +++ b/lib/chef/node_map.rb @@ -78,6 +78,10 @@ class Chef nil end + def delete(key) + @map.delete(key) + end + private # only allow valid filter options diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index ef0b59e4dc..280da8734c 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -978,14 +978,38 @@ class Chef super if subclass.dsl_name subclass.provides subclass.dsl_name.to_sym + subclass.instance_eval { @auto_provides = subclass.dsl_name.to_sym } end 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) + end + super + 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 + + 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) + end + end + # Helper for #notifies def validate_resource_spec!(resource_spec) run_context.resource_collection.validate_lookup_spec!(resource_spec) |