Sha256: 7669690def0fb5d103b0d395e251dc24a9ed88f3c2e5b8c889f09fa54bf1ce80

Contents?: true

Size: 775 Bytes

Versions: 2

Compression:

Stored size: 775 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 = Tempfile.new(["mini_magick", extension], MiniMagick.tmpdir, binmode: true)
      yield tempfile if block_given?
      tempfile.close
      tempfile
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mini_magick-5.0.1 lib/mini_magick/utilities.rb
mini_magick-5.0.0 lib/mini_magick/utilities.rb