Class: Shellter::Command
- Inherits:
-
Object
- Object
- Shellter::Command
- Defined in:
- lib/shellter/command.rb
Instance Attribute Summary collapse
-
#last_command ⇒ Object
readonly
Returns the value of attribute last_command.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
- #exit_code ⇒ Object
-
#initialize(command, *arguments) ⇒ Command
constructor
A new instance of Command.
- #run(options = {}) ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(command, *arguments) ⇒ Command
Returns a new instance of Command.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/shellter/command.rb', line 9 def initialize(command, *arguments) = arguments. @expected_outcodes = .delete(:expected_outcodes) @expected_outcodes ||= [0] @command = command @arguments = arguments @stdout = StringIO.new @stderr = StringIO.new end |
Instance Attribute Details
#last_command ⇒ Object (readonly)
Returns the value of attribute last_command.
7 8 9 |
# File 'lib/shellter/command.rb', line 7 def last_command @last_command end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
4 5 6 |
# File 'lib/shellter/command.rb', line 4 def pid @pid end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
6 7 8 |
# File 'lib/shellter/command.rb', line 6 def stderr @stderr end |
#stdout ⇒ Object (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_code ⇒ Object
39 40 41 |
# File 'lib/shellter/command.rb', line 39 def exit_code @status.to_i end |
#run(options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/shellter/command.rb', line 22 def run( = {}) with_env() do with_runner() do |runner| with_interpolated_command() do |command| @status = runner.run(command) do |stdout, stderr, stdin, pid| stdin.close @stdout.write(stdout.read) @stderr.write(stderr.read) @pid = pid end @stderr.rewind @stdout.rewind end end end end |
#success? ⇒ Boolean
43 44 45 |
# File 'lib/shellter/command.rb', line 43 def success? @expected_outcodes.include?(exit_code) end |