Class: HomebrewAutomation::MacOS

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

Overview

Inspect version of the macOS we’re running on

Class Method Summary collapse

Class Method Details

.identify_version!String | NilClass

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.

Returns:

  • (String | NilClass)


13
14
15
16
17
18
19
20
21
22
23
24
# 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_homebrewHash<Regexp, String>

Lookup table of numeric version patterns to Homebrew-recognised strings

Returns:

  • (Hash<Regexp, String>)


29
30
31
32
33
34
35
36
37
38
# 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