diff options
author | Serdar Sutay <serdar@opscode.com> | 2014-08-13 14:22:08 -0700 |
---|---|---|
committer | Serdar Sutay <serdar@opscode.com> | 2014-08-13 14:22:50 -0700 |
commit | c97046186d528adb43730a6806a6c1c781dc1b72 (patch) | |
tree | 83eaf32dd64d5e231a3a7e1fee360eacd78bec0a /lib | |
parent | cb172f8d54c665c8d27a6387b777178ebaea729b (diff) | |
download | chef-c97046186d528adb43730a6806a6c1c781dc1b72.tar.gz |
Merge pull request #1812 from opscode/sersut/chef-1773
Name :freebsd_package resource `package` to provide compat with ChefSpec.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/dsl/recipe.rb | 14 | ||||
-rw-r--r-- | lib/chef/resource/freebsd_package.rb | 12 |
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/chef/dsl/recipe.rb b/lib/chef/dsl/recipe.rb index 6846703f09..46788c046b 100644 --- a/lib/chef/dsl/recipe.rb +++ b/lib/chef/dsl/recipe.rb @@ -84,6 +84,20 @@ class Chef resource = build_resource(type, name, created_at, &resource_attrs_block) + # Some resources (freebsd_package) can be invoked with multiple names + # (package || freebsd_package). + # https://github.com/opscode/chef/issues/1773 + # For these resources we want to make sure + # their key in resource collection is same as the name they are declared + # as. Since this might be a breaking change for resources that define + # customer to_s methods, we are working around the issue by letting + # resources know of their created_as_type until this issue is fixed in + # Chef 12: + # https://github.com/opscode/chef/issues/1817 + if resource.respond_to?(:created_as_type=) + resource.created_as_type = type + end + run_context.resource_collection.insert(resource) resource end diff --git a/lib/chef/resource/freebsd_package.rb b/lib/chef/resource/freebsd_package.rb index c7a8d44181..70ef62ae8a 100644 --- a/lib/chef/resource/freebsd_package.rb +++ b/lib/chef/resource/freebsd_package.rb @@ -31,17 +31,26 @@ class Chef provides :package, :on_platforms => ["freebsd"] + attr_accessor :created_as_type def initialize(name, run_context=nil) super @resource_name = :freebsd_package + @created_as_type = "freebsd_package" end def after_created assign_provider end - + # This resource can be invoked with multiple names package & freebsd_package. + # We override the to_s method to ensure the key in resource collection + # matches the type resource is declared as using created_as_type. This + # logic can be removed once Chef does this for all resource in Chef 12: + # https://github.com/opscode/chef/issues/1817 + def to_s + "#{created_as_type}[#{name}]" + end private @@ -68,4 +77,3 @@ class Chef end end end - |