Class: Which::Base

Inherits:
Object show all
Defined in:
lib/pik/which.rb

Direct Known Subclasses

Gem, Irb, Rake, Ruby, SevenZip

Class Method Summary collapse

Class Method Details

.exe(path = find) ⇒ Object Also known as: bat



23
24
25
# File 'lib/pik/which.rb', line 23

def exe(path=find)
  glob(path).first
end

.exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/pik/which.rb', line 19

def exist?(path)
  !!exe(path)
end

.find(search_path = ENV['PATH']) ⇒ Object



7
8
9
10
11
# File 'lib/pik/which.rb', line 7

def find(search_path=ENV['PATH'])
  path = SearchPath.new(search_path)
  path = path.find{|dir| exist?(dir)}
  Pathname(path) rescue nil
end

.find_all(search_path = ENV['PATH']) ⇒ Object



13
14
15
16
17
# File 'lib/pik/which.rb', line 13

def find_all(search_path=ENV['PATH'])
  path = SearchPath.new(search_path)
  path = path.find_all{|dir| exist?(dir)}
  path.map{|i| Pathname(i) }
end

.glob(path) ⇒ Object



28
29
30
31
32
# File 'lib/pik/which.rb', line 28

def glob(path)
  return [] if path.nil?
  glob = "#{Pathname.new(path).to_ruby}/{#{executables.join(',')}}"
  Pathname.glob(glob)
end