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 56 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 end
parse_recipe_name(recipe_name, current_cookbook: nil)
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"] "::elastic_ip" returns [ current_cookbook, "elastic_ip" ]
# File lib/chef/recipe.rb, line 44 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 end
Public Instance Methods
inspect()
click to toggle source
# File lib/chef/recipe.rb, line 106 def inspect to_s end
node()
click to toggle source
Used in DSL mixins
# File lib/chef/recipe.rb, line 65 def node run_context.node end
tag(*tags)
click to toggle source
This was moved to Chef::Node#tag, redirecting here for compatibility
# File lib/chef/recipe.rb, line 70 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 82 def tagged?(*tags) tags.each do |tag| return false unless run_context.node.tags.include?(tag) end true end
to_s()
click to toggle source
# File lib/chef/recipe.rb, line 102 def to_s "cookbook: #{cookbook_name ? cookbook_name : "(none)"}, recipe: #{recipe_name ? recipe_name : "(none)"} " end