Class: Chef::Recipe
- Includes:
- Mixin::Deprecation, Mixin::FromFile, Mixin::Language, Mixin::LanguageIncludeRecipe, Mixin::RecipeDefinitionDSLCore
- Defined in:
- lib/chef/recipe.rb
Overview
Chef::Recipe
A Recipe object is the context in which Chef recipes are evaluated.
Instance Attribute Summary collapse
-
#cookbook_name ⇒ Object
Returns the value of attribute cookbook_name.
-
#params ⇒ Object
Returns the value of attribute params.
-
#recipe ⇒ Object
Returns the value of attribute recipe.
-
#recipe_name ⇒ Object
Returns the value of attribute recipe_name.
-
#run_context ⇒ Object
Returns the value of attribute run_context.
Class Method Summary collapse
-
.parse_recipe_name(recipe_name) ⇒ Object
Parses a potentially fully-qualified recipe name into its cookbook name and recipe short name.
Instance Method Summary collapse
-
#initialize(cookbook_name, recipe_name, run_context) ⇒ Recipe
constructor
A new instance of Recipe.
-
#node ⇒ Object
Used in DSL mixins.
-
#resources(*args) ⇒ Object
Used by the DSL to look up resources when executing in the context of a recipe.
-
#tag(*tags) ⇒ Object
Sets a tag, or list of tags, for this node.
-
#tagged?(*tags) ⇒ Boolean
Returns true if the node is tagged with all of the supplied
tags
. -
#untag(*tags) ⇒ Object
Removes the list of tags from the node.
Methods included from Mixin::Deprecation
Methods included from Mixin::RecipeDefinitionDSLCore
Methods included from Mixin::Language
#data_bag, #data_bag_item, #platform?, #platform_family?, #search, #value_for_platform, #value_for_platform_family
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Methods included from Mixin::LanguageIncludeRecipe
#include_recipe, #load_recipe, #require_recipe
Methods included from Mixin::FromFile
Constructor Details
#initialize(cookbook_name, recipe_name, run_context) ⇒ Recipe
Returns a new instance of Recipe.
58 59 60 61 62 63 64 65 |
# File 'lib/chef/recipe.rb', line 58 def initialize(cookbook_name, recipe_name, run_context) @cookbook_name = cookbook_name @recipe_name = recipe_name @run_context = run_context # TODO: 5/19/2010 cw/tim: determine whether this can be removed @params = Hash.new @node = deprecated_ivar(run_context.node, :node, :warn) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore
Instance Attribute Details
#cookbook_name ⇒ Object
Returns the value of attribute cookbook_name.
39 40 41 |
# File 'lib/chef/recipe.rb', line 39 def cookbook_name @cookbook_name end |
#params ⇒ Object
Returns the value of attribute params.
39 40 41 |
# File 'lib/chef/recipe.rb', line 39 def params @params end |
#recipe ⇒ Object
Returns the value of attribute recipe.
39 40 41 |
# File 'lib/chef/recipe.rb', line 39 def recipe @recipe end |
#recipe_name ⇒ Object
Returns the value of attribute recipe_name.
39 40 41 |
# File 'lib/chef/recipe.rb', line 39 def recipe_name @recipe_name end |
#run_context ⇒ Object
Returns the value of attribute run_context.
39 40 41 |
# File 'lib/chef/recipe.rb', line 39 def run_context @run_context end |
Class Method Details
.parse_recipe_name(recipe_name) ⇒ Object
Parses a potentially fully-qualified recipe name into its cookbook name and recipe short name.
For example:
"aws::elastic_ip" returns [:aws, "elastic_ip"]
"aws" returns [:aws, "default"]
– TODO: Duplicates functionality of RunListItem
49 50 51 52 53 54 55 56 |
# File 'lib/chef/recipe.rb', line 49 def self.parse_recipe_name(recipe_name) rmatch = recipe_name.match(/(.+?)::(.+)/) if rmatch [ rmatch[1].to_sym, rmatch[2] ] else [ recipe_name.to_sym, "default" ] end end |
Instance Method Details
#node ⇒ Object
Used in DSL mixins
68 69 70 |
# File 'lib/chef/recipe.rb', line 68 def node run_context.node end |
#resources(*args) ⇒ Object
Used by the DSL to look up resources when executing in the context of a recipe.
74 75 76 |
# File 'lib/chef/recipe.rb', line 74 def resources(*args) run_context.resource_collection.find(*args) end |
#tag(*tags) ⇒ Object
Sets a tag, or list of tags, for this node. Syntactic sugar for run_context.node.
With no arguments, returns the list of tags.
Parameters
- tags<Array>
-
A list of tags to add - can be a single string
Returns
- tags<Array>
-
The contents of run_context.node
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/chef/recipe.rb', line 88 def tag(*) if .length > 0 .each do |tag| tag = tag.to_s run_context.node[:tags] << tag unless run_context.node[:tags].include?(tag) end run_context.node[:tags] else run_context.node[:tags] end end |
#tagged?(*tags) ⇒ Boolean
Returns true if the node is tagged with all of the supplied tags
.
Parameters
- tags<Array>
-
A list of tags
Returns
- true<TrueClass>
-
If all the parameters are present
- false<FalseClass>
-
If any of the parameters are missing
108 109 110 111 112 113 |
# File 'lib/chef/recipe.rb', line 108 def tagged?(*) .each do |tag| return false unless run_context.node[:tags].include?(tag) end true end |
#untag(*tags) ⇒ Object
Removes the list of tags from the node.
Parameters
- tags<Array>
-
A list of tags
Returns
- tags<Array>
-
The current list of run_context.node
122 123 124 125 126 |
# File 'lib/chef/recipe.rb', line 122 def untag(*) .each do |tag| run_context.node[:tags].delete(tag) end end |