Class: ShellCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/shell_commands/shell_command.rb

Constant Summary collapse

@@results =
[]
@@last_result =
nil
@@error_proc =
nil

Class Method Summary collapse

Class Method Details

.do_command(command) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/shell_commands/shell_command.rb', line 31

def self.do_command(command)
  if !raw_do_command(command)
    if @@error_proc.nil?
      raise ShellCommandFailure.new(@@last_result)
    else
      @@error_proc.call(@@last_result)
    end
    return false
  end
  return true
end

.error_procObject



10
11
12
# File 'lib/shell_commands/shell_command.rb', line 10

def self.error_proc
  @@error_proc
end

.last_resultObject



7
8
9
# File 'lib/shell_commands/shell_command.rb', line 7

def self.last_result
  @@last_result
end

.raw_do_command(command) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/shell_commands/shell_command.rb', line 17

def self.raw_do_command(command)
  result = %x[#{command} 2>&1]
  while not $?.exited? do
  end

  @@last_result = {
    "command" => command, 
    "result" => result, 
    "success" => $?.success?
  }
  @@results << @@last_result
  return $?.success?
end

.resultsObject



13
14
15
# File 'lib/shell_commands/shell_command.rb', line 13

def self.results
  @@results
end