From d638ce43c7cf2208ff0db16db695212b7609b481 Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Thu, 29 Nov 2012 16:10:31 -0800 Subject: [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. --- lib/chef/run_context/cookbook_compiler.rb | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'lib/chef/run_context/cookbook_compiler.rb') 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 -- cgit v1.2.1