Class: Escort::Formatter::ShellCommandExecutor
- Inherits:
-
Object
- Object
- Escort::Formatter::ShellCommandExecutor
- Defined in:
- lib/escort/formatter/shell_command_executor.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Instance Method Summary collapse
- #execute_in_current_shell(success_callback = nil, error_callback = nil) ⇒ Object
-
#initialize(command) ⇒ ShellCommandExecutor
constructor
A new instance of ShellCommandExecutor.
Constructor Details
#initialize(command) ⇒ ShellCommandExecutor
Returns a new instance of ShellCommandExecutor.
8 9 10 |
# File 'lib/escort/formatter/shell_command_executor.rb', line 8 def initialize(command) @command = command end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
6 7 8 |
# File 'lib/escort/formatter/shell_command_executor.rb', line 6 def command @command end |
Instance Method Details
#execute_in_current_shell(success_callback = nil, error_callback = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/escort/formatter/shell_command_executor.rb', line 12 def execute_in_current_shell(success_callback = nil, error_callback = nil) begin result = `#{command}` process_status = $? raise Escort::InternalError.new("Shell command exited with a non-zero (#{process_status.exitstatus}) exit code") if process_status.exitstatus != 0 success_callback.call(command, result) if success_callback rescue => e error_callback.call(command, e) if error_callback nil end end |