Sha256: 0d15d30acf54c636175c691f083999c8fb360174a481523003fadccc221f2c57

Contents?: true

Size: 694 Bytes

Versions: 5

Compression:

Stored size: 694 Bytes

Contents

module Teabag
  module Utility

    # Cross-platform way of finding an executable in the $PATH.
    # http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
    #
    # @example
    #   which('ruby') #=> /usr/bin/ruby
    #
    # @param cmd [String] the executable to find
    # @return [String, nil] the path to the executable
    #
    def which(cmd)
      exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']

      ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
        exts.each do |ext|
          exe = "#{ path }/#{ cmd }#{ ext }"
          return exe if File.executable?(exe)
        end
      end

      nil
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
teabag-0.7.3 lib/teabag/utility.rb
teabag-0.7.2 lib/teabag/utility.rb
teabag-0.7.1 lib/teabag/utility.rb
teabag-0.7.0 lib/teabag/utility.rb
teabag-0.6.0 lib/teabag/utility.rb