Sha256: 7f9016c30c8d2f716f0b11f85195caa79c07621006f4452440d84d5ba14d455d

Contents?: true

Size: 1.09 KB

Versions: 20

Compression:

Stored size: 1.09 KB

Contents

require 'English'

class ImageOptim
  # Helper for running commands
  module Cmd
    class << self
      # Run using `system`
      # Return success status
      # Will raise SignalException if process was interrupted
      def run(*args)
        success = system(*args)

        check_status!

        success
      end

      # Run using backtick
      # Return captured output
      # Will raise SignalException if process was interrupted
      def capture(cmd)
        output = `#{cmd}`

        check_status!

        output
      end

    private

      def check_status!
        status = $CHILD_STATUS

        return unless status.signaled?

        # jruby incorrectly returns true for `signaled?` if process exits with
        # non zero status. For following code
        #
        #     `sh -c 'exit 66'`
        #     p [$?.signaled?, $?.exitstatus, $?.termsig]
        #
        # jruby outputs `[true, 66, 66]` instead of expected `[false, 66, nil]`
        return if defined?(JRUBY_VERSION) && status.exitstatus == status.termsig

        fail SignalException, status.termsig
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
image_optim-0.26.3 lib/image_optim/cmd.rb
image_optim-0.26.2 lib/image_optim/cmd.rb
image_optim-0.26.1 lib/image_optim/cmd.rb
image_optim-0.26.0 lib/image_optim/cmd.rb
image_optim-0.25.0 lib/image_optim/cmd.rb
image_optim-0.24.3 lib/image_optim/cmd.rb
image_optim-0.24.2 lib/image_optim/cmd.rb
image_optim-0.24.1 lib/image_optim/cmd.rb
image_optim-0.24.0 lib/image_optim/cmd.rb
image_optim-0.23.0 lib/image_optim/cmd.rb
image_optim-0.22.1 lib/image_optim/cmd.rb
image_optim-0.22.0 lib/image_optim/cmd.rb
openstreetmap-image_optim-0.21.0.1 lib/image_optim/cmd.rb
image_optim-0.21.0 lib/image_optim/cmd.rb
image_optim-0.20.2 lib/image_optim/cmd.rb
image_optim-0.20.1 lib/image_optim/cmd.rb
image_optim-0.20.0 lib/image_optim/cmd.rb
image_optim-0.19.1 lib/image_optim/cmd.rb
image_optim-0.19.0 lib/image_optim/cmd.rb
image_optim-0.18.0 lib/image_optim/cmd.rb