Class: Coque::Result

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/coque/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid, out) ⇒ Result

Returns a new instance of Result.



5
6
7
8
# File 'lib/coque/result.rb', line 5

def initialize(pid, out)
  @pid = pid
  @out = out
end

Instance Attribute Details

#exit_codeObject (readonly)

Returns the value of attribute exit_code.



2
3
4
# File 'lib/coque/result.rb', line 2

def exit_code
  @exit_code
end

#pidObject (readonly)

Returns the value of attribute pid.



2
3
4
# File 'lib/coque/result.rb', line 2

def pid
  @pid
end

Instance Method Details

#each(&block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/coque/result.rb', line 10

def each(&block)
  begin
    @out.each_line do |line|
      block.call(line.chomp)
    end
  rescue IOError
    # If the command was redirected to an existing standard output stream,
    # i.e. $stdout or $stderr, that output will be streamed as executed, so
    # attempting to read from it here will fail.
    # There may be a better way to handle this case, but for now this is working ok.
  end
  unless defined? @exit_code
    wait
  end
end

#success?Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/coque/result.rb', line 32

def success?
  count
  exit_code == 0
end

#waitObject



26
27
28
29
30
# File 'lib/coque/result.rb', line 26

def wait
  _pid, status = Process.waitpid2(pid)
  @exit_code = status.exitstatus
  self
end