diff options
author | John Keiser <john@johnkeiser.com> | 2015-12-02 16:45:32 -0800 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-12-02 16:45:32 -0800 |
commit | 3d7440aae2f78f99d63ed4a24b5b1f3c5b1da8a8 (patch) | |
tree | 7ebfe5f31203e06088cd3d0d257dd366c6c599ef /lib | |
parent | de1f684f415faa54599c6b3abbe211d64a319aa6 (diff) | |
download | chef-3d7440aae2f78f99d63ed4a24b5b1f3c5b1da8a8.tar.gz |
Converge actions all together instead of in action :x (fixes #4124)jk/4124
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/provider.rb | 49 |
1 files changed, 15 insertions, 34 deletions
diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb index d4cce075e5..3ddf33844f 100644 --- a/lib/chef/provider.rb +++ b/lib/chef/provider.rb @@ -351,10 +351,20 @@ class Chef # @api private module InlineResources - # Our run context is a child of the main run context; that gives us a - # whole new resource collection and notification set. - def initialize(resource, run_context) - super(resource, run_context.create_child) + # Create a child run_context, compile the block, and converge it. + # + # @api private + def compile_and_converge_action(&block) + old_run_context = run_context + @run_context = run_context.create_child + return_value = instance_eval(&block) + Chef::Runner.new(run_context).converge + return_value + ensure + if run_context.resource_collection.any? { |r| r.updated? } + new_resource.updated_by_last_action(true) + end + @run_context = old_run_context end # Class methods for InlineResources. Overrides the `action` DSL method @@ -366,36 +376,7 @@ class Chef # compile the resources, converging them, and then checking if any # were updated (and updating new-resource if so) def action(name, &block) - # We first try to create the method using "def method_name", which is - # preferred because it actually shows up in stack traces. If that - # fails, we try define_method. - begin - class_eval <<-EOM, __FILE__, __LINE__+1 - def action_#{name} - return_value = compile_action_#{name} - Chef::Runner.new(run_context).converge - return_value - ensure - if run_context.resource_collection.any? {|r| r.updated? } - new_resource.updated_by_last_action(true) - end - end - EOM - rescue SyntaxError - define_method("action_#{name}") do - begin - return_value = send("compile_action_#{name}") - Chef::Runner.new(run_context).converge - return_value - ensure - if run_context.resource_collection.any? {|r| r.updated? } - new_resource.updated_by_last_action(true) - end - end - end - end - # We put the action in its own method so that super() works. - define_method("compile_action_#{name}", &block) + define_method("action_#{name}") { compile_and_converge_action(&block) } end end |