summaryrefslogtreecommitdiff
path: root/lib/chef/recipe.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-01-20 10:16:17 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2015-01-20 10:21:10 -0800
commit35276fd91c5aec8986723504b8a490e5823b770e (patch)
tree5ea6d3a89ebc905d816753160d290e8a76199e0b /lib/chef/recipe.rb
parentb622710cd1ee8af39bc3ff255e2394c0115abaac (diff)
downloadchef-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.rb12
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