Class: Bookingit::ShellCommand
- Inherits:
-
Object
- Object
- Bookingit::ShellCommand
- Includes:
- FileUtils
- Defined in:
- lib/bookingit/shell_command.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#exit_code ⇒ Object
readonly
Returns the value of attribute exit_code.
-
#expected_exit_status ⇒ Object
readonly
Returns the value of attribute expected_exit_status.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
-
#initialize(command: nil, path: '.', expected_exit_status: 0, &block) ⇒ ShellCommand
constructor
A new instance of ShellCommand.
- #run! ⇒ Object
Constructor Details
#initialize(command: nil, path: '.', expected_exit_status: 0, &block) ⇒ ShellCommand
Returns a new instance of ShellCommand.
10 11 12 13 14 15 16 17 18 |
# File 'lib/bookingit/shell_command.rb', line 10 def initialize(command: nil,path: '.',expected_exit_status: 0, &block) @command = command @path = path @exit_status_checker = if block.nil? ->(exit_code) { exit_code == expected_exit_status } else block end end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
8 9 10 |
# File 'lib/bookingit/shell_command.rb', line 8 def command @command end |
#exit_code ⇒ Object (readonly)
Returns the value of attribute exit_code.
8 9 10 |
# File 'lib/bookingit/shell_command.rb', line 8 def exit_code @exit_code end |
#expected_exit_status ⇒ Object (readonly)
Returns the value of attribute expected_exit_status.
8 9 10 |
# File 'lib/bookingit/shell_command.rb', line 8 def expected_exit_status @expected_exit_status end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
8 9 10 |
# File 'lib/bookingit/shell_command.rb', line 8 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
8 9 10 |
# File 'lib/bookingit/shell_command.rb', line 8 def stdout @stdout end |
Instance Method Details
#run! ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/bookingit/shell_command.rb', line 20 def run! chdir @path do @stdout, @stderr, status = Open3.capture3(@command) @exit_code = status.exitstatus end unless @exit_status_checker.(@exit_code) raise UnexpectedShellCommandExit.new(@command,@stdout,@stderr) end end |