Module: ObjectiveCommand::Shell::Attribute

Defined in:
lib/objective_command/shell.rb

Overview

class Simple

Instance Method Summary collapse

Instance Method Details

#shell(*args, &block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/objective_command/shell.rb', line 56

def shell *args, &block
  local_shell = ocmd_shell
  unless args.empty?
    runner = ocmd_shell.runner
    options = {}
    for arg in args.flatten do
      case arg
        when OCmd::Runners::Runner then runner = arg
        when Hash then options.merge! arg
        when Symbol then options[arg] = true
        else raise ArgumentError, "Bad argument: #{arg}"
      end
    end
    local_shell = Shell::Simple.new runner, options
  end
  if block
    block.bind(local_shell).call
  else
    local_shell
  end
end

#shell!(*args, &block) ⇒ Object

Raises:

  • (ArgumentError)


78
79
80
81
82
# File 'lib/objective_command/shell.rb', line 78

def shell! *args, &block
  raise ArgumentError, 'Block needed' if block.nil?
  local_shell = shell(*args)
  block.bind(local_shell).call.run local_shell.runner 
end