class Chef::Recipe
Chef::Recipe¶ ↑
A Recipe object is the context in which Chef recipes are evaluated.
Attributes
cookbook_name[RW]
params[RW]
recipe[RW]
recipe_name[RW]
run_context[RW]
Public Class Methods
new(cookbook_name, recipe_name, run_context)
click to toggle source
# File lib/chef/recipe.rb, line 66 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
parse_recipe_name(recipe_name)
click to toggle source
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"]
# File lib/chef/recipe.rb, line 57 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
Public Instance Methods
node()
click to toggle source
Used in DSL mixins
# File lib/chef/recipe.rb, line 76 def node run_context.node end
resources(*args)
click to toggle source
Used by the DSL to look up resources when executing in the context of a recipe.
# File lib/chef/recipe.rb, line 82 def resources(*args) run_context.resource_collection.find(*args) end
tag(*tags)
click to toggle source
This was moved to Chef::Node#tag, redirecting here for compatability
# File lib/chef/recipe.rb, line 87 def tag(*tags) run_context.node.tag(*tags) end
tagged?(*tags)
click to toggle source
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
# File lib/chef/recipe.rb, line 99 def tagged?(*tags) tags.each do |tag| return false unless run_context.node[:tags].include?(tag) end true end
untag(*tags)
click to toggle source
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
# File lib/chef/recipe.rb, line 113 def untag(*tags) tags.each do |tag| run_context.node.normal[:tags].delete(tag) end end