Sha256: e5dd380a30cd2842fa103faf3e57f0c5d4826b03b67505d0bb201c0e3772e095

Contents?: true

Size: 766 Bytes

Versions: 50

Compression:

Stored size: 766 Bytes

Contents

# frozen_string_literal: true

# 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

50 entries across 50 versions & 1 rubygems

Version Path
quality-40.0.1 lib/quality/which.rb
quality-40.0.0 lib/quality/which.rb
quality-39.0.1 lib/quality/which.rb
quality-38.0.1 lib/quality/which.rb
quality-38.0.0 lib/quality/which.rb
quality-37.1.1 lib/quality/which.rb
quality-37.1.0 lib/quality/which.rb
quality-37.0.1 lib/quality/which.rb
quality-37.0.0 lib/quality/which.rb
quality-36.1.0 lib/quality/which.rb
quality-36.0.0 lib/quality/which.rb
quality-35.2.1 lib/quality/which.rb
quality-35.2.0 lib/quality/which.rb
quality-35.1.1 lib/quality/which.rb
quality-35.0.1 lib/quality/which.rb
quality-35.0.0 lib/quality/which.rb
quality-34.0.2 lib/quality/which.rb
quality-34.0.1 lib/quality/which.rb
quality-34.0.0 lib/quality/which.rb
quality-33.0.0 lib/quality/which.rb