Module: MiniMagick::Utilities
- Defined in:
- lib/mini_magick/utilities.rb
Class Method Summary collapse
-
.which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
-
.windows? ⇒ Boolean
Finds out if the host OS is windows.
- .windows_escape(cmdline) ⇒ Object
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 { |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable? exe } end return nil end |
.windows? ⇒ Boolean
Finds out if the host OS is windows
21 22 23 |
# File 'lib/mini_magick/utilities.rb', line 21 def windows? RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ end |
.windows_escape(cmdline) ⇒ Object
25 26 27 |
# File 'lib/mini_magick/utilities.rb', line 25 def windows_escape(cmdline) '"' + cmdline.gsub(/\\(?=\\*\")/, "\\\\\\").gsub(/\"/, "\\\"").gsub(/\\$/, "\\\\\\").gsub("%", "%%") + '"' end |