Class: ScoobyDoo

Inherits:
Object
  • Object
show all
Defined in:
lib/scoobydoo.rb

Constant Summary collapse

@@cache =
Hash.new

Class Method Summary collapse

Class Method Details

.where_are_you(cmd) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/scoobydoo.rb', line 6

def self.where_are_you(cmd)
    return nil if (cmd.nil? || cmd.empty?)
    return @@cache[cmd] if (@@cache.has_key?(cmd))

    if (cmd.include?(File::SEPARATOR))
        exe = Pathname.new(cmd).expand_path
        return (exe.executable? && !exe.directory?) ? exe : nil
    end

    exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
    ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
        exts.each do |ext|
            exe = File.join(path, "#{cmd}#{ext}")
            if (File.executable?(exe) && !File.directory?(exe))
                @@cache[cmd] = exe
                return exe
            end
        end
    end

    return nil
end