Class: Chef::Recipe

Inherits:
Object show all
Includes:
Mixin::FromFile, Mixin::Language, Mixin::LanguageIncludeRecipe, Mixin::RecipeDefinitionDSLCore
Defined in:
lib/chef/recipe.rb,
lib/chef/shef/ext.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Methods included from Mixin::Language

#data_bag, #data_bag_item, #platform?, #search, #value_for_platform

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string

Methods included from Mixin::LanguageIncludeRecipe

#include_recipe, #require_recipe

Methods included from Mixin::FromFile

#class_from_file, #from_file

Constructor Details

#initialize(cookbook_name, recipe_name, node, collection = nil, definitions = nil, cookbook_loader = nil) ⇒ Recipe

Returns a new instance of Recipe.



41
42
43
44
45
46
47
48
49
# File 'lib/chef/recipe.rb', line 41

def initialize(cookbook_name, recipe_name, node, collection=nil, definitions=nil, cookbook_loader=nil)
  @cookbook_name = cookbook_name
  @recipe_name = recipe_name
  @node = node
  @collection = collection || Chef::ResourceCollection.new
  @definitions = definitions || Hash.new
  @cookbook_loader = cookbook_loader || Chef::CookbookLoader.new
  @params = Hash.new      
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



38
39
40
# File 'lib/chef/recipe.rb', line 38

def collection
  @collection
end

#cookbook_loaderObject

Returns the value of attribute cookbook_loader.



38
39
40
# File 'lib/chef/recipe.rb', line 38

def cookbook_loader
  @cookbook_loader
end

#cookbook_nameObject

Returns the value of attribute cookbook_name.



38
39
40
# File 'lib/chef/recipe.rb', line 38

def cookbook_name
  @cookbook_name
end

#definitionsObject

Returns the value of attribute definitions.



38
39
40
# File 'lib/chef/recipe.rb', line 38

def definitions
  @definitions
end

#nodeObject

Returns the value of attribute node.



38
39
40
# File 'lib/chef/recipe.rb', line 38

def node
  @node
end

#paramsObject

Returns the value of attribute params.



38
39
40
# File 'lib/chef/recipe.rb', line 38

def params
  @params
end

#recipeObject

Returns the value of attribute recipe.



38
39
40
# File 'lib/chef/recipe.rb', line 38

def recipe
  @recipe
end

#recipe_nameObject

Returns the value of attribute recipe_name.



38
39
40
# File 'lib/chef/recipe.rb', line 38

def recipe_name
  @recipe_name
end

Instance Method Details

#original_resourcesObject



285
286
287
# File 'lib/chef/shef/ext.rb', line 285

def resources(*args)
  @collection.resources(*args)
end

#resources(*args) ⇒ Object



51
52
53
# File 'lib/chef/recipe.rb', line 51

def resources(*args)
  @collection.resources(*args)
end

#shef_helpObject



281
282
283
# File 'lib/chef/shef/ext.rb', line 281

def shef_help
  super("Help: Shef/Recipe")
end

#tag(*args) ⇒ Object

Sets a tag, or list of tags, for this node. Syntactic sugar for @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 @node



65
66
67
68
69
70
71
72
73
74
# File 'lib/chef/recipe.rb', line 65

def tag(*args)
  if args.length > 0
    args.each do |tag|
      @node[:tags] << tag unless @node[:tags].include?(tag)
    end
    @node[:tags]
  else
    @node[:tags]
  end
end

#tagged?(*args) ⇒ Boolean

Returns true if the node is tagged with the supplied list of 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

Returns:

  • (Boolean)


84
85
86
87
88
89
# File 'lib/chef/recipe.rb', line 84

def tagged?(*args)
  args.each do |tag|
    return false unless @node[:tags].include?(tag)
  end
  true
end

#untag(*args) ⇒ Object

Removes the list of tags from the node.

Parameters

tags<Array>

A list of tags

Returns

tags<Array>

The current list of @node



98
99
100
101
102
# File 'lib/chef/recipe.rb', line 98

def untag(*args)
  args.each do |tag|
    @node[:tags].delete(tag)
  end
end