Module: MiniMagick::Utilities

Defined in:
lib/mini_magick/utilities.rb

Class Method Summary collapse

Class Method Details

.tempfile(extension) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/mini_magick/utilities.rb', line 26

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

.which(cmd) ⇒ Object

Cross-platform way of finding an executable in the $PATH.

Examples:

MiniMagick::Utilities.which('ruby') #=> "/usr/bin/ruby"


15
16
17
18
19
20
21
22
23
24
# File 'lib/mini_magick/utilities.rb', line 15

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