forked from concerto/concerto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_check.rb
39 lines (33 loc) · 891 Bytes
/
command_check.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#Cross-platform way of finding an executable in the $PATH
#which('ruby') #=> /usr/bin/ruby
#Courtesy of Mislav Marohnic (via Stackoverflow)
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = "#{path}/#{cmd}#{ext}"
return exe if File.executable? exe
}
end
return nil
end
#Check for existence of a command for use
def command?(command)
if which(command) != nil
return true
else
return false
end
end
def system_has_mysql?
Gem::Specification::find_all_by_name('mysql2').any? || command?('mysql_config')
end
def system_has_postgres?
Gem::Specification::find_all_by_name('pg').any? || command?('pg_config')
end
def mysql_location
which('mysql_config').split('/bin').first
end
def postgres_location
which('pg_config').split('/bin').first
end