# File lib/chef/resource/conditional.rb, line 46 def initialize(positivity, parent_resource, command=nil, command_opts={}, &block) @positivity = positivity case command when String @guard_interpreter = new_guard_interpreter(parent_resource, command, command_opts, &block) @command, @command_opts = command, command_opts @block = nil when nil raise ArgumentError, "only_if/not_if requires either a command or a block" unless block_given? @guard_interpreter = nil @command, @command_opts = nil, nil @block = block else raise ArgumentError, "Invalid only_if/not_if command: #{command.inspect} (#{command.class})" end end
# File lib/chef/resource/conditional.rb, line 63 def continue? case @positivity when :only_if evaluate when :not_if !evaluate else raise "Cannot evaluate resource conditional of type #{@positivity}" end end
# File lib/chef/resource/conditional.rb, line 93 def description cmd_or_block = @command ? "command `#{@command}`" : "ruby block" "#{@positivity} #{cmd_or_block}" end
# File lib/chef/resource/conditional.rb, line 74 def evaluate @guard_interpreter ? evaluate_command : evaluate_block end
# File lib/chef/resource/conditional.rb, line 85 def evaluate_block @block.call end
# File lib/chef/resource/conditional.rb, line 78 def evaluate_command @guard_interpreter.evaluate rescue Chef::Exceptions::CommandTimeout Chef::Log.warn "Command '#{@command}' timed out" false end
Generated with the Darkfish Rdoc Generator 2.