Class: Cuken::Api::Aruba::Process
- Inherits:
-
Object
- Object
- Cuken::Api::Aruba::Process
- Includes:
- Shellwords
- Defined in:
- lib/cuken/api/aruba/process.rb
Instance Method Summary collapse
-
#initialize(cmd, exit_timeout, io_wait) ⇒ Process
constructor
A new instance of Process.
- #output ⇒ Object
- #remove_ansi_codes(str) ⇒ Object
- #run! {|_self| ... } ⇒ Object
- #stderr ⇒ Object
- #stdin ⇒ Object
- #stdout ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(cmd, exit_timeout, io_wait) ⇒ Process
Returns a new instance of Process.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cuken/api/aruba/process.rb', line 15 def initialize(cmd, exit_timeout, io_wait) @exit_timeout = exit_timeout @io_wait = io_wait @out = ::Tempfile.new("aruba-out") @err = ::Tempfile.new("aruba-err") @process = ChildProcess.build(*shellwords(cmd)) @process.io.stdout = @out @process.io.stderr = @err @process.duplex = true end |
Instance Method Details
#output ⇒ Object
38 39 40 |
# File 'lib/cuken/api/aruba/process.rb', line 38 def output stdout + stderr end |
#remove_ansi_codes(str) ⇒ Object
11 12 13 |
# File 'lib/cuken/api/aruba/process.rb', line 11 def remove_ansi_codes(str) str.gsub(/\e\[(\d+)m/, '') end |
#run! {|_self| ... } ⇒ Object
27 28 29 30 |
# File 'lib/cuken/api/aruba/process.rb', line 27 def run!(&block) @process.start yield self if block_given? end |
#stderr ⇒ Object
49 50 51 52 53 54 |
# File 'lib/cuken/api/aruba/process.rb', line 49 def stderr wait_for_io do @err.rewind remove_ansi_codes(@err.read) end end |
#stdin ⇒ Object
32 33 34 35 36 |
# File 'lib/cuken/api/aruba/process.rb', line 32 def stdin wait_for_io do @process.io.stdin end end |
#stdout ⇒ Object
42 43 44 45 46 47 |
# File 'lib/cuken/api/aruba/process.rb', line 42 def stdout wait_for_io do @out.rewind remove_ansi_codes(@out.read) end end |
#stop ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/cuken/api/aruba/process.rb', line 56 def stop if @process stdout && stderr # flush output @process.poll_for_exit(@exit_timeout) @process.exit_code end end |