Class: Tonic::Shell
- Inherits:
-
String
- Object
- String
- Tonic::Shell
- Defined in:
- lib/tonic/shell.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#out ⇒ Object
readonly
Returns the value of attribute out.
Class Method Summary collapse
Instance Method Summary collapse
- #command ⇒ Object
- #error? ⇒ Boolean
-
#initialize(*command) ⇒ Shell
constructor
A new instance of Shell.
- #out? ⇒ Boolean
- #run ⇒ Object
Constructor Details
#initialize(*command) ⇒ Shell
Returns a new instance of Shell.
16 17 18 |
# File 'lib/tonic/shell.rb', line 16 def initialize(*command) @command = command end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
9 10 11 |
# File 'lib/tonic/shell.rb', line 9 def error @error end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
10 11 12 |
# File 'lib/tonic/shell.rb', line 10 def out @out end |
Class Method Details
.run(*command) ⇒ Object
12 13 14 |
# File 'lib/tonic/shell.rb', line 12 def self.run(*command) self.new(*command).run end |
Instance Method Details
#command ⇒ Object
33 34 35 |
# File 'lib/tonic/shell.rb', line 33 def command @command.join(' ') end |
#error? ⇒ Boolean
37 38 39 |
# File 'lib/tonic/shell.rb', line 37 def error? !!@error end |
#out? ⇒ Boolean
41 42 43 |
# File 'lib/tonic/shell.rb', line 41 def out? !!@out end |
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tonic/shell.rb', line 20 def run out = err = nil Open3.popen3(*@command) do |_, pout, perr| out = pout.read.strip err = perr.read.strip end replace @error = err unless err.empty? replace @out = out unless out.empty? self end |