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
# 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      
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



34
35
36
# File 'lib/shellter/command.rb', line 34

def exit_code
  @status.to_i
end

#run(options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/shellter/command.rb', line 19

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 = stdout.read
          @stderr = stderr.read
          @pid = pid
        end
      end
    end
  end
end

#success?Boolean

Returns:

  • (Boolean)


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

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