diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-03-13 15:18:03 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-08-18 12:03:21 -0700 |
commit | 63a2d95003bc062d251d453d63ab1c5d91cbdb06 (patch) | |
tree | 5f50177a3cd8c66242030e198e2c1387ab4d56f6 /lib/chef/mixin | |
parent | 74e6bd6b50af383829f4bfc47ca18a4e089b1428 (diff) | |
download | chef-63a2d95003bc062d251d453d63ab1c5d91cbdb06.tar.gz |
CHEF-5012: add methods for template breadcrumbs
adds:
- cookbook_name
- recipe_name
- recipe_line_string
- recipe_path
- recipe_line
- template_name
- template_path
accessible both as instance var (@-) and method (bare), like @node/node.
Diffstat (limited to 'lib/chef/mixin')
-rw-r--r-- | lib/chef/mixin/template.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/chef/mixin/template.rb b/lib/chef/mixin/template.rb index d705a9e7be..546b76cf80 100644 --- a/lib/chef/mixin/template.rb +++ b/lib/chef/mixin/template.rb @@ -58,11 +58,58 @@ class Chef # by the bare `node` everywhere. def node return @node if @node + # XXX: we include @node even if you explicitly pass vars, so is this warning never reached? raise "Could not find a value for node. If you are explicitly setting variables in a template, " + "include a node variable if you plan to use it." end # + # Helpers for adding context of which resource is rendering the template (CHEF-5012) + # + + # name of the cookbook containing the template resource, e.g.: + # test + def cookbook_name + return @cookbook_name if @cookbook_name + end + + # name of the recipe containing the template resource, e.g.: + # default + def recipe_name + return @recipe_name if @recipe_name + end + + # string representation of the line in the recipe containing the template resource, e.g.: + # /Users/lamont/solo/cookbooks/test/recipes/default.rb:2:in `from_file' + def recipe_line_string + return @recipe_line_string if @recipe_line_string + end + + # path to the recipe containing the template resource, e.g.: + # /Users/lamont/solo/cookbooks/test/recipes/default.rb + def recipe_path + return @recipe_path if @recipe_path + end + + # line in the recipe containing the template reosurce, e.g.: + # 2 + def recipe_line + return @recipe_line if @recipe_line + end + + # name of the template source itself, e.g.: + # foo.erb + def template_name + return @template_name if @template_name + end + + # path to the template source itself, e.g.: + # /Users/lamont/solo/cookbooks/test/templates/default/foo.erb + def template_path + return @template_path if @template_path + end + + # # Takes the name of the partial, plus a hash of options. Returns a # string that contains the result of the evaluation of the partial. # |