Sha256: a0f46a008fe53fb2a2770409e444a3998ac82a974bc9a2439f5de956db79984b

Contents?: true

Size: 735 Bytes

Versions: 15

Compression:

Stored size: 735 Bytes

Contents

# http://stackoverflow.com/questions/2108727/
#   which-in-ruby-checking-if-program-exists-in-path-from-ruby
module Quality
  # Determine where a given executable lives, like the UNIX 'which' command
  class Which
    def initialize(env: ENV,
                   file: File,
                   separator: File::PATH_SEPARATOR)
      @env = env
      @file = file
      @separator = separator
    end

    def which(cmd)
      exts = @env['PATHEXT'] ? @env['PATHEXT'].split(';') : ['']
      @env['PATH'].split(@separator).each do |path|
        exts.each do |ext|
          exe = @file.join(path, "#{cmd}#{ext}")
          return exe if @file.executable?(exe) && !@file.directory?(exe)
        end
      end
      nil
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
quality-22.0.0 lib/quality/which.rb
quality-21.0.6 lib/quality/which.rb
quality-21.0.5 lib/quality/which.rb
quality-21.0.4 lib/quality/which.rb
quality-21.0.3 lib/quality/which.rb
quality-21.0.2 lib/quality/which.rb
quality-21.0.1 lib/quality/which.rb
quality-20.1.1 lib/quality/which.rb
quality-21.0.0 lib/quality/which.rb
quality-20.1.0 lib/quality/which.rb
quality-20.0.3 lib/quality/which.rb
quality-20.0.2 lib/quality/which.rb
quality-20.0.1 lib/quality/which.rb
quality-20.0.0 lib/quality/which.rb
quality-19.2.1 lib/quality/which.rb