Class: ChromeInstalledChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/chrome_installed_checker.rb

Defined Under Namespace

Classes: ChromeError, ChromeNotInstalled, ChromeVersionError, ChromeVersionTooLow

Class Method Summary collapse

Class Method Details

.runObject

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/chrome_installed_checker.rb', line 15

def self.run
  if RbConfig::CONFIG["host_os"][/darwin|mac os/]
    binary = "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
  elsif system("command -v google-chrome-stable >/dev/null;")
    binary = "google-chrome-stable"
  end
  binary ||= "google-chrome" if system("command -v google-chrome >/dev/null;")
  binary ||= "chromium" if system("command -v chromium >/dev/null;")

  if !binary
    raise ChromeNotInstalled.new(
            "Chrome is not installed. Download from https://www.google.com/chrome/browser/desktop/index.html",
          )
  end

  version = `\"#{binary}\" --version`
  version_match = version.match(/[\d\.]+/)

  raise ChromeError.new("Can't get the #{binary} version") if !version_match

  if Gem::Version.new(version_match[0]) < Gem::Version.new("59")
    raise ChromeVersionTooLow.new("Chrome 59 or higher is required")
  end
end