Sha256: adda5128df657e1cf6b029113a6065505a2914a3788aaed0927058278c6271da

Contents?: true

Size: 739 Bytes

Versions: 4

Compression:

Stored size: 739 Bytes

Contents

require "pathname"

module Teaspoon
  def self.root
    defined?(Rails) ? Rails.root : Pathname.new(Dir.pwd)
  end

  def self.abort(message = nil, code = 1)
    STDOUT.print("#{message}\n") if message
    exit(code)
  end

  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
    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.file?(exe) && File.executable?(exe)
        end
      end

      nil
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
teaspoon-1.4.0 lib/teaspoon/utility.rb
teaspoon-1.2.2 lib/teaspoon/utility.rb
teaspoon-1.2.1 lib/teaspoon/utility.rb
teaspoon-1.2.0 lib/teaspoon/utility.rb