module Chauffeur::PathExpander
Adds locations of drivers for the current platform to the beginning of the path
Public Class Methods
current_chromedriver_platform()
click to toggle source
# File lib/chauffeur/path_expander.rb, line 19 def self.current_chromedriver_platform case RbConfig::CONFIG['host_os'] when 'mingw32' 'win32' when 'mac', /darwin/ 'mac32' else RbConfig::CONFIG['host_cpu'].eql?('x86_64') ? 'linux64' : 'linux32' end end
current_geckodriver_platform()
click to toggle source
# File lib/chauffeur/path_expander.rb, line 36 def self.current_geckodriver_platform case RbConfig::CONFIG['host_os'] when 'mingw32' ENV['architecture'].eql?('64') ? 'win64' : 'win32' when 'mac', /darwin/ 'macos' else RbConfig::CONFIG['host_cpu'].eql?('x86_64') ? 'linux64' : 'linux32' end end
current_iedriver_platform()
click to toggle source
# File lib/chauffeur/path_expander.rb, line 51 def self.current_iedriver_platform ENV['architecture'].eql?('64') ? 'x64' : 'Win32' end
format_for_platform(path, platform = nil)
click to toggle source
Takes a file path and puts the appropriate slashes for the operating system.
# File lib/chauffeur/path_expander.rb, line 63 def self.format_for_platform(path, platform = nil) host_os = platform || RbConfig::CONFIG['host_os'] if host_os.eql?('mingw32') path.tr('/', '\\') elsif host_os.include?('linux') || host_os.include?('mac') || host_os.include?('darwin') path.tr('\\', '/') else raise UnknownPlatformError, platform end end
make_driver_executable(file_path)
click to toggle source
# File lib/chauffeur/path_expander.rb, line 90 def self.make_driver_executable(file_path) return if windows? File.chmod(0o0777, file_path) if File.exist?(file_path) end
path_to_chromedriver(platform = nil)
click to toggle source
# File lib/chauffeur/path_expander.rb, line 13 def self.path_to_chromedriver(platform = nil) driver_path = "#{Dir.pwd}/drivers/chromedriver/#{platform || current_chromedriver_platform}" make_driver_executable("#{driver_path}/chromedriver") driver_path end
path_to_edgedriver(platform = nil)
click to toggle source
# File lib/chauffeur/path_expander.rb, line 55 def self.path_to_edgedriver(platform = nil) return nil unless windows_10? p = platform || windows_build_number "#{Dir.pwd}/drivers/microsoft_webdriver/#{p}" end
path_to_geckodriver(platform = nil)
click to toggle source
# File lib/chauffeur/path_expander.rb, line 30 def self.path_to_geckodriver(platform = nil) driver_path = "#{Dir.pwd}/drivers/geckodriver/#{platform || current_geckodriver_platform}" make_driver_executable("#{driver_path}/geckodriver") driver_path end
path_to_iedriver(platform = nil)
click to toggle source
# File lib/chauffeur/path_expander.rb, line 47 def self.path_to_iedriver(platform = nil) windows? ? "#{Dir.pwd}/drivers/iedriver/#{platform || current_iedriver_platform}" : nil end
paths_to_add()
click to toggle source
# File lib/chauffeur/path_expander.rb, line 4 def self.paths_to_add all_paths = [path_to_chromedriver, path_to_geckodriver, path_to_iedriver, path_to_edgedriver].compact # paths = all_paths.compact.join(Gem.path_separator) + Gem.path_separator all_paths.map { |p| format_for_platform(p) } end
windows?()
click to toggle source
# File lib/chauffeur/path_expander.rb, line 74 def self.windows? RbConfig::CONFIG['host_os'].eql?('mingw32') end
windows_10?()
click to toggle source
# File lib/chauffeur/path_expander.rb, line 78 def self.windows_10? windows? && windows_version.eql?('Version 10') end
windows_build_number()
click to toggle source
# File lib/chauffeur/path_expander.rb, line 86 def self.windows_build_number `ver`.match(/\.(\d+)\]/)[1] end
windows_version()
click to toggle source
# File lib/chauffeur/path_expander.rb, line 82 def self.windows_version `ver`.match(/(Version \d+)/)[1] end