Class: Jiveapps::Shell

Inherits:
String
  • Object
show all
Defined in:
lib/jiveapps/shell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ Shell

Returns a new instance of Shell.



11
12
13
# File 'lib/jiveapps/shell.rb', line 11

def initialize(command)
  @command = command
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



7
8
9
# File 'lib/jiveapps/shell.rb', line 7

def error
  @error
end

#exit_statusObject (readonly)

Returns the value of attribute exit_status.



9
10
11
# File 'lib/jiveapps/shell.rb', line 9

def exit_status
  @exit_status
end

#outObject (readonly)

Returns the value of attribute out.



8
9
10
# File 'lib/jiveapps/shell.rb', line 8

def out
  @out
end

Instance Method Details

#commandObject



32
33
34
# File 'lib/jiveapps/shell.rb', line 32

def command
  @command.join(' ')
end

#error?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/jiveapps/shell.rb', line 36

def error?
  @exit_status != 0
end

#out?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/jiveapps/shell.rb', line 40

def out?
  !!@out
end

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jiveapps/shell.rb', line 15

def run
  out = err = nil

  begin
    status, out, err = systemu(@command)
  rescue => e
    puts e.inspect
  end

  @exit_status = status.exitstatus

  replace @error = err unless err.empty?
  replace @out   = out unless out.empty?

  self
end