diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-01-20 10:16:17 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-01-20 10:21:10 -0800 |
commit | 35276fd91c5aec8986723504b8a490e5823b770e (patch) | |
tree | 5ea6d3a89ebc905d816753160d290e8a76199e0b /lib/chef/recipe.rb | |
parent | b622710cd1ee8af39bc3ff255e2394c0115abaac (diff) | |
download | chef-35276fd91c5aec8986723504b8a490e5823b770e.tar.gz |
make include_recipe "::foo" use current cookbook
The following code is brittle if you want to fork the cookbook and rename it
(which is a best practice when forking cookbooks for internal use):
```ruby
if node[:platform_family] == "rhel"
include_recipe "mycookbook::_rhel"
end
```
In order for cookbooks to be easily renamable they can currently use the
syntax `include_recipe "#{cookbook_name}::_rhel"` which is unwieldy.
This patch adds `include_recipe "::_rhel"` as syntax sugar to make this
easier.
Diffstat (limited to 'lib/chef/recipe.rb')
-rw-r--r-- | lib/chef/recipe.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/chef/recipe.rb b/lib/chef/recipe.rb index 621d93099b..91f7f30aa9 100644 --- a/lib/chef/recipe.rb +++ b/lib/chef/recipe.rb @@ -54,12 +54,16 @@ class Chef # For example: # "aws::elastic_ip" returns [:aws, "elastic_ip"] # "aws" returns [:aws, "default"] + # "::elastic_ip" returns [ current_cookbook, "elastic_ip" ] #-- # TODO: Duplicates functionality of RunListItem - def self.parse_recipe_name(recipe_name) - rmatch = recipe_name.match(/(.+?)::(.+)/) - if rmatch - [ rmatch[1].to_sym, rmatch[2] ] + def self.parse_recipe_name(recipe_name, current_cookbook: nil) + case recipe_name + when /(.+?)::(.+)/ + [ $1.to_sym, $2 ] + when /^::(.+)/ + raise "current_cookbook is nil, cannot resolve #{recipe_name}" if current_cookbook.nil? + [ current_cookbook.to_sym, $1 ] else [ recipe_name.to_sym, "default" ] end |