summaryrefslogtreecommitdiff
path: root/lib/chef/resource.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-08-03 14:38:03 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2018-08-03 14:38:03 -0700
commit83ab18515911416ae3622dbcfd44c2ce56b76546 (patch)
tree4ed70f284155027c8052d5df797c59bc05104d47 /lib/chef/resource.rb
parent628b6189201c532ae0e3ff962b324018911ff389 (diff)
downloadchef-83ab18515911416ae3622dbcfd44c2ce56b76546.tar.gz
add chef_version API to provides lines
also adds the chef_version_for_provides helper method Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/resource.rb')
-rw-r--r--lib/chef/resource.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index d341e401de..f65af0c7eb 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -1305,6 +1305,26 @@ class Chef
end
#
+ # This API can be used for backcompat to do:
+ #
+ # chef_version_for_provides "< 14.0" if defined?(:chef_version_for_provides)
+ #
+ # For core chef versions that do not support chef_version: in provides lines.
+ #
+ # Since resource_name calls provides the generally correct way of doing this is
+ # to do `chef_version_for_provides` first, then `resource_name` and then
+ # any additional options `provides` lines. Calling `resource_name` is somewhat
+ # important to have the canonical_dsl removed or else that'll stick around
+ # and chef_version won't get applied to it.
+ #
+ # Once we no longer care about supporting chef < 14.4 then we can deprecate
+ # this API.
+ #
+ def self.chef_version_for_provides(arg)
+ @chef_version_for_provides = arg
+ end
+
+ #
# Mark this resource as providing particular DSL.
#
# Resources have an automatic DSL based on their resource_name, equivalent to
@@ -1327,6 +1347,10 @@ class Chef
options[:allow_cookbook_override] = true
end
+ if @chef_version_for_provides && !options.include?(:chef_version)
+ options[:chef_version] = @chef_version_for_provides
+ end
+
result = Chef.resource_handler_map.set(name, self, options, &block)
Chef::DSL::Resources.add_resource_dsl(name)
result