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 |
# File 'lib/shellter/command.rb', line 9 def initialize(command, *arguments) = arguments. @expected_outcodes = .delete(:expected_outcodes) @expected_outcodes ||= [0] @command = command @arguments = arguments 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
34 35 36 |
# File 'lib/shellter/command.rb', line 34 def exit_code @status.to_i end |
#run(options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/shellter/command.rb', line 19 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 = stdout.read @stderr = stderr.read @pid = pid end end end end end |
#success? ⇒ Boolean
38 39 40 |
# File 'lib/shellter/command.rb', line 38 def success? @expected_outcodes.include?(exit_code) end |