Sha256: add16d8e0aae16bcf39d42cfbae3058327223cf35ab71ca4a6835b14bc7d0557

Contents?: true

Size: 824 Bytes

Versions: 6

Compression:

Stored size: 824 Bytes

Contents

require 'fileutils'
require 'open3'

module Bookingit
  class ShellCommand
    include FileUtils

    attr_reader :stdout, :stderr, :exit_code, :command, :expected_exit_status

    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

    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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bookingit-0.5.0 lib/bookingit/shell_command.rb
bookingit-0.4.1 lib/bookingit/shell_command.rb
bookingit-0.4.0 lib/bookingit/shell_command.rb
bookingit-0.3.0 lib/bookingit/shell_command.rb
bookingit-0.2.0 lib/bookingit/shell_command.rb
bookingit-0.1.0 lib/bookingit/shell_command.rb