Module: Chef::Mixin::NotifyingBlock

Included in:
DSL::Core
Defined in:
lib/chef/mixin/notifying_block.rb

Instance Method Summary collapse

Instance Method Details

#notifying_block(&block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/chef/mixin/notifying_block.rb', line 22

def notifying_block(&block)
  subcontext = subcontext_block(&block)
  Chef::Runner.new(subcontext).converge
ensure
  # recipes don't have a new_resource
  if respond_to?(:new_resource)
    if subcontext && subcontext.resource_collection.any?(&:updated?)
      new_resource.updated_by_last_action(true)
    end
  end
end

#subcontext_block(parent_context = nil, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/chef/mixin/notifying_block.rb', line 34

def subcontext_block(parent_context = nil, &block)
  parent_context ||= @run_context
  sub_run_context = parent_context.create_child

  begin
    outer_run_context = @run_context
    @run_context = sub_run_context
    instance_eval(&block)
  ensure
    @run_context = outer_run_context
  end

  sub_run_context
end