Class: Chef::Recipe

Inherits:
Object
  • Object
show all
Includes:
DSL::Recipe, Mixin::Deprecation, Mixin::FromFile
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

Attributes included from Mixin::FromFile

#source_file

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::Deprecation

#deprecated_attr, #deprecated_attr_reader, #deprecated_attr_writer, #deprecated_ivar

Methods included from Mixin::FromFile

#class_from_file, #from_file

Methods included from DSL::Recipe

#exec, #have_resource_class_for?, #resource_class_for

Methods included from Mixin::LazyModuleInclude

#descendants, #include, #included

Methods included from DSL::Definitions

add_definition, #evaluate_resource_definition, #has_resource_definition?

Methods included from DSL::Resources

add_resource_dsl, remove_resource_dsl

Methods included from DSL::Cheffish

load_cheffish

Methods included from DSL::RebootPending

#reboot_pending?

Methods included from DSL::PlatformIntrospection

#older_than_win_2012_or_8?, #platform?, #platform_family?, #value_for_platform, #value_for_platform_family

Methods included from DSL::RegistryHelper

#registry_data_exists?, #registry_get_subkeys, #registry_get_values, #registry_has_subkeys?, #registry_key_exists?, #registry_value_exists?

Methods included from DSL::IncludeRecipe

#include_recipe, #load_recipe

Methods included from Mixin::NotifyingBlock

#notifying_block, #subcontext_block

Methods included from DSL::DeclareResource

#build_resource, #declare_resource, #delete_resource, #delete_resource!, #edit_resource, #edit_resource!, #find_resource, #find_resource!, #resources, #with_run_context

Methods included from Mixin::ShellOut

apply_default_env, maybe_add_timeout, #shell_out, #shell_out!

Methods included from Mixin::PowershellOut

#powershell_out, #powershell_out!

Methods included from Mixin::WindowsArchitectureHelper

#assert_valid_windows_architecture!, #disable_wow64_file_redirection, #forced_32bit_override_required?, #is_i386_process_on_x86_64_windows?, #node_supports_windows_architecture?, #node_windows_architecture, #restore_wow64_file_redirection, #valid_windows_architecture?, #with_os_architecture, #wow64_architecture_override_required?, #wow64_directory

Methods included from Mixin::PowershellExec

#powershell_exec

Methods included from DSL::Powershell

#ps_credential

Methods included from DSL::DataQuery

#data_bag, #data_bag_item, #search, #tagged?

Methods included from EncryptedDataBagItem::CheckEncrypted

#encrypted?

Constructor Details

#initialize(cookbook_name, recipe_name, run_context) ⇒ Recipe

Returns a new instance of Recipe.



57
58
59
60
61
62
63
# File 'lib/chef/recipe.rb', line 57

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 = {}
end

Instance Attribute Details

#cookbook_nameObject

Returns the value of attribute cookbook_name.



28
29
30
# File 'lib/chef/recipe.rb', line 28

def cookbook_name
  @cookbook_name
end

#paramsObject

Returns the value of attribute params.



28
29
30
# File 'lib/chef/recipe.rb', line 28

def params
  @params
end

#recipeObject

Returns the value of attribute recipe.



28
29
30
# File 'lib/chef/recipe.rb', line 28

def recipe
  @recipe
end

#recipe_nameObject

Returns the value of attribute recipe_name.



28
29
30
# File 'lib/chef/recipe.rb', line 28

def recipe_name
  @recipe_name
end

#run_contextObject

Returns the value of attribute run_context.



28
29
30
# File 'lib/chef/recipe.rb', line 28

def run_context
  @run_context
end

Class Method Details

.parse_recipe_name(recipe_name, current_cookbook: nil) ⇒ 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"]
"::elastic_ip" returns [ current_cookbook, "elastic_ip" ]

– TODO: Duplicates functionality of RunListItem



44
45
46
47
48
49
50
51
52
53
54
55
# 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

Instance Method Details

#inspectObject



92
93
94
# File 'lib/chef/recipe.rb', line 92

def inspect
  to_s
end

#nodeObject

Used in DSL mixins



66
67
68
# File 'lib/chef/recipe.rb', line 66

def node
  run_context.node
end

#tag(*tags) ⇒ Object

This was moved to Chef::Node#tag, redirecting here for compatibility



71
72
73
# File 'lib/chef/recipe.rb', line 71

def tag(*tags)
  run_context.node.tag(*tags)
end

#to_sObject



88
89
90
# File 'lib/chef/recipe.rb', line 88

def to_s
  "cookbook: #{cookbook_name ? cookbook_name : "(none)"}, recipe: #{recipe_name ? recipe_name : "(none)"} "
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.tags



82
83
84
85
86
# File 'lib/chef/recipe.rb', line 82

def untag(*tags)
  tags.each do |tag|
    run_context.node.tags.delete(tag)
  end
end