Module: MiniMagick::Utilities

Defined in:
lib/mini_magick/utilities.rb

Class Method Summary collapse

Class Method Details

.which(cmd) ⇒ Object

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

which('ruby') #=> /usr/bin/ruby


9
10
11
12
13
14
15
16
17
18
# File 'lib/mini_magick/utilities.rb', line 9

def which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['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

.windows?Boolean

Finds out if the host OS is windows

Returns:

  • (Boolean)


21
22
23
# File 'lib/mini_magick/utilities.rb', line 21

def windows?
  RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
end

.windows_escape(value) ⇒ Object



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

def windows_escape(value)
  # For Windows, ^ is the escape char, equivalent to \ in Unix.
  escaped = value.gsub(/\^/, '^^').gsub(/>/, '^>')
  if escaped !~ /^".+"$/ && escaped.include?("'")
    escaped.inspect
  else
    escaped
  end
end