Sha256: 44bda6808bc71426de1c102073006a9c34a6419d1b8b865fb1c418a6da5cfd71

Contents?: true

Size: 773 Bytes

Versions: 15

Compression:

Stored size: 773 Bytes

Contents

require "tempfile"

module MiniMagick
  # @private
  module Utilities

    module_function

    ##
    # Cross-platform way of finding an executable in the $PATH.
    #
    # @example
    #   MiniMagick::Utilities.which('ruby') #=> "/usr/bin/ruby"
    #
    def which(cmd)
      exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
      ENV.fetch('PATH').split(File::PATH_SEPARATOR).each do |path|
        exts.each do |ext|
          exe = File.join(path, "#{cmd}#{ext}")
          return exe if File.executable? exe
        end
      end
      nil
    end

    def tempfile(extension)
      Tempfile.new(["mini_magick", extension]).tap do |tempfile|
        tempfile.binmode
        yield tempfile if block_given?
        tempfile.close
      end
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mini_magick-4.11.0 lib/mini_magick/utilities.rb
mini_magick-4.10.1 lib/mini_magick/utilities.rb
mini_magick-4.10.0 lib/mini_magick/utilities.rb
mini_magick-4.9.5 lib/mini_magick/utilities.rb
mini_magick-4.9.4 lib/mini_magick/utilities.rb
mini_magick-4.9.3 lib/mini_magick/utilities.rb
mini_magick-4.9.2 lib/mini_magick/utilities.rb
mini_magick-4.9.1 lib/mini_magick/utilities.rb
mini_magick-4.9.0 lib/mini_magick/utilities.rb
mini_magick-4.8.0 lib/mini_magick/utilities.rb
mini_magick-4.7.2 lib/mini_magick/utilities.rb
mini_magick-4.7.1 lib/mini_magick/utilities.rb
mini_magick-4.7.0 lib/mini_magick/utilities.rb
mini_magick-4.6.1 lib/mini_magick/utilities.rb
mini_magick-4.6.0 lib/mini_magick/utilities.rb