lib/chef/mixin/command.rb in chef-0.10.6.beta.2 vs lib/chef/mixin/command.rb in chef-0.10.6.beta.3

- old
+ new

@@ -36,67 +36,9 @@ require 'chef/mixin/command/unix' include ::Chef::Mixin::Command::Unix extend ::Chef::Mixin::Command::Unix end - # If command is a block, returns true if the block returns true, false if it returns false. - # ("Only run this resource if the block is true") - # - # If the command is not a block, executes the command. If it returns any status other than - # 0, it returns false (clearly, a 0 status code is true) - # - # === Parameters - # command<Block>, <String>:: A block to check, or a string to execute - # - # === Returns - # true:: Returns true if the block is true, or if the command returns 0 - # false:: Returns false if the block is false, or if the command returns a non-zero exit code. - def only_if(command, args = {}) - if command.kind_of?(Proc) - chdir_or_tmpdir(args[:cwd]) do - res = command.call - unless res - return false - end - end - else - status = run_command({:command => command, :ignore_failure => true}.merge(args)) - if status.exitstatus != 0 - return false - end - end - true - end - - # If command is a block, returns false if the block returns true, true if it returns false. - # ("Do not run this resource if the block is true") - # - # If the command is not a block, executes the command. If it returns a 0 exitstatus, returns false. - # ("Do not run this resource if the command returns 0") - # - # === Parameters - # command<Block>, <String>:: A block to check, or a string to execute - # - # === Returns - # true:: Returns true if the block is false, or if the command returns a non-zero exit status. - # false:: Returns false if the block is true, or if the command returns a 0 exit status. - def not_if(command, args = {}) - if command.kind_of?(Proc) - chdir_or_tmpdir(args[:cwd]) do - res = command.call - if res - return false - end - end - else - status = run_command({:command => command, :ignore_failure => true}.merge(args)) - if status.exitstatus == 0 - return false - end - end - true - end - # === Parameters # args<Hash>: A number of required and optional arguments # command<String>, <Array>: A complete command with options to execute or a command and options as an Array # creates<String>: The absolute path to a file that prevents the command from running if it exists # cwd<String>: Working directory to execute command in, defaults to Dir.tmpdir