summaryrefslogtreecommitdiff
path: root/lib/chef/run_context/cookbook_compiler.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2012-11-29 16:10:31 -0800
committerdanielsdeleo <dan@opscode.com>2012-11-30 14:51:48 -0800
commitd638ce43c7cf2208ff0db16db695212b7609b481 (patch)
treeb61c0b6ec030c0655cab80d71010127383250847 /lib/chef/run_context/cookbook_compiler.rb
parent20fd1383020261c3756b54c26f4c2ea9e652d43c (diff)
downloadchef-d638ce43c7cf2208ff0db16db695212b7609b481.tar.gz
[CHEF-3376] make CookbookCompiler take a RunContext
The circular reference is not ideal, but it allows for complete extraction of all cookbook compilation into CookbookCompiler.
Diffstat (limited to 'lib/chef/run_context/cookbook_compiler.rb')
-rw-r--r--lib/chef/run_context/cookbook_compiler.rb32
1 files changed, 16 insertions, 16 deletions
diff --git a/lib/chef/run_context/cookbook_compiler.rb b/lib/chef/run_context/cookbook_compiler.rb
index 8edc1ade3c..5192fab9b4 100644
--- a/lib/chef/run_context/cookbook_compiler.rb
+++ b/lib/chef/run_context/cookbook_compiler.rb
@@ -28,30 +28,30 @@ class Chef
# Implements the compile phase of the chef run by loading/eval-ing files
# from cookbooks in the correct order and in the correct context.
class CookbookCompiler
- attr_reader :node
attr_reader :events
attr_reader :run_list_expansion
- attr_reader :cookbook_collection
# Resource Definitions from the compiled cookbooks. This is populated by
# calling #compile_resource_definitions (which is called by #compile)
attr_reader :definitions
- def initialize(node, cookbook_collection, run_list_expansion, events)
- @node = node
+ def initialize(run_context, run_list_expansion, events)
+ @run_context = run_context
@events = events
@run_list_expansion = run_list_expansion
- @cookbook_collection = cookbook_collection
+ @cookbook_order = nil
+ end
- # @resource_collection = Chef::ResourceCollection.new
- # @immediate_notification_collection = Hash.new {|h,k| h[k] = []}
- # @delayed_notification_collection = Hash.new {|h,k| h[k] = []}
- # @loaded_recipes = {}
- # @loaded_attributes = {}
- #
+ def node
+ @run_context.node
+ end
- @definitions = Hash.new
- @cookbook_order = nil
+ def cookbook_collection
+ @run_context.cookbook_collection
+ end
+
+ def definitions
+ @run_context.definitions
end
# Run the compile phase of the chef run. Loads files in the following order:
@@ -121,6 +121,7 @@ class Chef
@events.lwrp_load_complete
end
+ # Loads resource definitions according to #cookbook_order
def compile_resource_definitions
@events.definition_load_start(count_files_by_segment(:definitions))
cookbook_order.each do |cookbook|
@@ -129,7 +130,6 @@ class Chef
@events.definition_load_complete
end
-
private
def load_attributes_from_cookbook(cookbook_name)
@@ -145,9 +145,9 @@ class Chef
end
def load_attribute_file(cookbook_name, filename)
- Chef::Log.debug("Node #{@node.name} loading cookbook #{cookbook_name}'s attribute file #{filename}")
+ Chef::Log.debug("Node #{node.name} loading cookbook #{cookbook_name}'s attribute file #{filename}")
attr_file_basename = ::File.basename(filename, ".rb")
- @node.include_attribute("#{cookbook_name}::#{attr_file_basename}")
+ node.include_attribute("#{cookbook_name}::#{attr_file_basename}")
rescue Exception => e
@events.attribute_file_load_failed(filename, e)
raise