Class: Media::Command::Subshell
- Inherits:
-
Object
- Object
- Media::Command::Subshell
- Extended by:
- Forwardable
- Defined in:
- lib/media/command/subshell.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#out ⇒ Object
readonly
Returns the value of attribute out.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(args) ⇒ Subshell
constructor
A new instance of Subshell.
- #success? ⇒ Boolean
Constructor Details
#initialize(args) ⇒ Subshell
Returns a new instance of Subshell.
12 13 14 |
# File 'lib/media/command/subshell.rb', line 12 def initialize(args) @cmd = Array(args.fetch(:cmd)) end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
10 11 12 |
# File 'lib/media/command/subshell.rb', line 10 def error @error end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
10 11 12 |
# File 'lib/media/command/subshell.rb', line 10 def out @out end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
10 11 12 |
# File 'lib/media/command/subshell.rb', line 10 def status @status end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/media/command/subshell.rb', line 16 def call @out, @error, @status = Open3.popen3(*@cmd) {|stdin,stdout,stderr,thread| out = Thread.new do stdout.each_with_object([]) do |line, memo| memo << line yield line.strip if block_given? end.join end err = Thread.new do stderr.each_with_object([]) do |line, memo| memo << line yield line.strip if block_given? end.join end stdin.close [out.value, err.value, thread.value] } self end |
#success? ⇒ Boolean
40 41 42 |
# File 'lib/media/command/subshell.rb', line 40 def success? exitstatus == 0 end |