Path: blob/trunk/rake_tasks/selenium_rake/checks.rb
1864 views
# frozen_string_literal: true12require 'rbconfig'34module SeleniumRake5class Checks6class << self7PRESENT_CACHE = {}89def windows?10(RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw32/) != nil11end1213def mac?14(RbConfig::CONFIG['host_os'] =~ /darwin|mac os/) != nil15end1617def linux?18!windows? && !mac?19end2021def dir_separator22File::ALT_SEPARATOR || File::SEPARATOR23end2425def path_for(path)26windows? ? path.gsub('/', dir_separator) : path27end2829def classpath_separator?30if cygwin?31';'32else33File::PATH_SEPARATOR34end35end3637def chrome?38present?('chromedriver') || present?('chromedriver.exe')39end4041def edge?42present?('msedgedriver') || present?('msedgedriver.exe')43end4445def opera?46present?('opera') || present?('Opera')47end4849def python?50present?('python') || present?('python.exe')51end5253private5455def cygwin?56RUBY_PLATFORM.downcase.include?('cygwin')57end5859def present?(arg)60return PRESENT_CACHE[arg] if PRESENT_CACHE.key?(arg)61return PRESENT_CACHE[arg] = true if exist_on_non_mac?(arg)62return PRESENT_CACHE[arg] = exist_on_mac?(arg) if mac?63PRESENT_CACHE[arg] = false64end6566def exist_on_non_mac?(arg)67prefixes.any? do |prefix|68File.exist?("#{prefix}#{File::SEPARATOR}#{arg}")69end70end7172def exist_on_mac?(arg)73File.exist?("/Applications/#{arg}.app")74end7576def prefixes77ENV['PATH'].split(File::PATH_SEPARATOR)78end79end80end81end828384