-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
/
Copy pathchecks.rb
82 lines (64 loc) · 1.67 KB
/
checks.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# frozen_string_literal: true
require 'rbconfig'
module SeleniumRake
class Checks
class << self
PRESENT_CACHE = {}
def windows?
(RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw32/) != nil
end
def mac?
(RbConfig::CONFIG['host_os'] =~ /darwin|mac os/) != nil
end
def linux?
!windows? && !mac?
end
def dir_separator
File::ALT_SEPARATOR || File::SEPARATOR
end
def path_for(path)
windows? ? path.gsub('/', dir_separator) : path
end
def classpath_separator?
if cygwin?
';'
else
File::PATH_SEPARATOR
end
end
def chrome?
present?('chromedriver') || present?('chromedriver.exe')
end
def edge?
present?('msedgedriver') || present?('msedgedriver.exe')
end
def opera?
present?('opera') || present?('Opera')
end
def python?
present?('python') || present?('python.exe')
end
private
def cygwin?
RUBY_PLATFORM.downcase.include?('cygwin')
end
def present?(arg)
return PRESENT_CACHE[arg] if PRESENT_CACHE.key?(arg)
return PRESENT_CACHE[arg] = true if exist_on_non_mac?(arg)
return PRESENT_CACHE[arg] = exist_on_mac?(arg) if mac?
PRESENT_CACHE[arg] = false
end
def exist_on_non_mac?(arg)
prefixes.any? do |prefix|
File.exist?("#{prefix}#{File::SEPARATOR}#{arg}")
end
end
def exist_on_mac?(arg)
File.exist?("/Applications/#{arg}.app")
end
def prefixes
ENV['PATH'].split(File::PATH_SEPARATOR)
end
end
end
end