Class: Shellter::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/shellter/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, *arguments) ⇒ Command

Returns a new instance of Command.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/shellter/command.rb', line 9

def initialize(command, *arguments)
  options = arguments.extract_options!

  @expected_outcodes = options.delete(:expected_outcodes)
  @expected_outcodes ||= [0]

  @command = command
  @arguments = arguments 
  
  @stdout = StringIO.new     
  @stderr = StringIO.new     
end

Instance Attribute Details

#last_commandObject (readonly)

Returns the value of attribute last_command.



7
8
9
# File 'lib/shellter/command.rb', line 7

def last_command
  @last_command
end

#pidObject (readonly)

Returns the value of attribute pid.



4
5
6
# File 'lib/shellter/command.rb', line 4

def pid
  @pid
end

#stderrObject (readonly)

Returns the value of attribute stderr.



6
7
8
# File 'lib/shellter/command.rb', line 6

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



5
6
7
# File 'lib/shellter/command.rb', line 5

def stdout
  @stdout
end

Instance Method Details

#exit_codeObject



39
40
41
# File 'lib/shellter/command.rb', line 39

def exit_code
  @status.to_i
end

#run(options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/shellter/command.rb', line 22

def run(options = {})
  with_env(options) do
    with_runner(options) do |runner|
      with_interpolated_command(options) do |command|
        @status = runner.run(command) do |stdout, stderr, stdin, pid|
          stdin.close
          @stdout.write(stdout.read)
          @stderr.write(stderr.read)
          @pid = pid
        end
        @stderr.rewind
        @stdout.rewind
      end
    end
  end
end

#success?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/shellter/command.rb', line 43

def success?
  @expected_outcodes.include?(exit_code)
end