class HomebrewAutomation::MacOS

Inspect version of the macOS we're running on

Public Class Methods

identify_version!() click to toggle source

Identify the version of the macOS this is run on

Return a macOS version name in a convention recognised by Homebrew, in particular by the Formula/Bottle DSL.

@return [String | NilClass]

# File lib/homebrew_automation/mac_os.rb, line 13
def self.identify_version!
  version =
    begin
      `sw_vers -productVersion`.chomp
    rescue Errno::ENOENT    # if we're not on a Mac
      nil
    end
  mac_to_homebrew.
    select { |pattern, _| pattern === version }.
    map { |_, description| description }.
    first
end
mac_to_homebrew() click to toggle source

Lookup table of numeric version patterns to Homebrew-recognised strings

@return [Hash<Regexp, String>]

# File lib/homebrew_automation/mac_os.rb, line 29
def self.mac_to_homebrew
  {
    /^10.10/ => 'yosemite',
    /^10.11/ => 'el_capitan',
    /^10.12/ => 'sierra',
    /^10.13/ => 'high_sierra',
    /^10.14/ => 'mojave',
    /^10.15/ => 'catalina'
  }
end