Class: Chef::GuardInterpreter::ResourceGuardInterpreter
- Inherits:
-
DefaultGuardInterpreter
- Object
- DefaultGuardInterpreter
- Chef::GuardInterpreter::ResourceGuardInterpreter
- Defined in:
- lib/chef/guard_interpreter/resource_guard_interpreter.rb
Instance Method Summary collapse
- #evaluate ⇒ Object
-
#initialize(parent_resource, command, opts) ⇒ ResourceGuardInterpreter
constructor
A new instance of ResourceGuardInterpreter.
Methods included from Mixin::ShellOut
apply_default_env, maybe_add_timeout, #shell_out, #shell_out!
Constructor Details
#initialize(parent_resource, command, opts) ⇒ ResourceGuardInterpreter
Returns a new instance of ResourceGuardInterpreter.
25 26 27 28 29 |
# File 'lib/chef/guard_interpreter/resource_guard_interpreter.rb', line 25 def initialize(parent_resource, command, opts) super(command, opts) @parent_resource = parent_resource @resource = get_interpreter_resource(parent_resource) end |
Instance Method Details
#evaluate ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/chef/guard_interpreter/resource_guard_interpreter.rb', line 31 def evaluate # Add attributes inherited from the parent class # to the resource merge_inherited_attributes # Only execute and script resources and use guard attributes. # The command to be executed on them are passed via different attributes. # Script resources use code attribute and execute resources use # command property. Moreover script resources are also execute # resources. Here we make sure @command is assigned to the right # attribute by checking the type of the resources. # We need to make sure we check for Script first because any resource # that can get to here is an Execute resource. if @resource.is_a? Chef::Resource::Script block_attributes = @command_opts.merge({ code: @command }) else block_attributes = @command_opts.merge({ command: @command }) end # Handles cases like powershell_script where default # attributes are different when used in a guard vs. not. For # powershell_script in particular, this will go away when # the one attribue that causes this changes its default to be # the same after some period to prepare for deprecation if @resource.class.respond_to?(:get_default_attributes) block_attributes = @resource.class.send(:get_default_attributes, @command_opts).merge(block_attributes) end resource_block = block_from_attributes(block_attributes) evaluate_action(nil, &resource_block) end |