Class: Chef::RunContext

Inherits:
Object show all
Includes:
Mixin::LanguageIncludeRecipe
Defined in:
lib/chef/run_context.rb

Overview

Chef::RunContext

Value object that loads and tracks the context of a Chef run

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin::LanguageIncludeRecipe

#include_recipe, #require_recipe

Constructor Details

#initialize(node, cookbook_collection) ⇒ RunContext

Creates a new Chef::RunContext object and populates its fields. This object gets used by the Chef Server to generate a fully compiled recipe list for a node.

Returns

object<Chef::RunContext>

Duh. :)



45
46
47
48
49
50
51
52
53
54
# File 'lib/chef/run_context.rb', line 45

def initialize(node, cookbook_collection)
  @node = node
  @cookbook_collection = cookbook_collection
  @resource_collection = Chef::ResourceCollection.new
  @definitions = Hash.new

  # TODO: 5/18/2010 cw/timh - See note on Chef::Node's
  # cookbook_collection attr_accessor
  node.cookbook_collection = cookbook_collection
end

Instance Attribute Details

#cookbook_collectionObject (readonly)

Returns the value of attribute cookbook_collection.



34
35
36
# File 'lib/chef/run_context.rb', line 34

def cookbook_collection
  @cookbook_collection
end

#definitionsObject (readonly)

Returns the value of attribute definitions.



34
35
36
# File 'lib/chef/run_context.rb', line 34

def definitions
  @definitions
end

#nodeObject (readonly)

Returns the value of attribute node.



34
35
36
# File 'lib/chef/run_context.rb', line 34

def node
  @node
end

#resource_collectionObject

Needs to be settable so deploy can run a resource_collection independent of any cookbooks.



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

def resource_collection
  @resource_collection
end

Instance Method Details

#load(run_list_expansion) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/chef/run_context.rb', line 56

def load(run_list_expansion)
  load_libraries
  load_lwrp_providers
  load_lwrp_resources
  load_attributes
  load_resource_definitions

  # Precendence rules state that roles' attributes come after
  # cookbooks. Now we've loaded attributes from cookbooks with
  # load_attributes, apply the expansion attributes (loaded from
  # roles) to the node.
  @node.apply_expansion_attributes(run_list_expansion)

  run_list_expansion.recipes.each do |recipe|
    # TODO: timh/cw, 5-14-2010: It's distasteful to be including
    # the DSL in a class outside the context of the DSL
    include_recipe(recipe)
  end
end