Class: MacOSRequirement Private

Inherits:
Requirement show all
Defined in:
Library/Homebrew/requirements/macos_requirement.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A requirement on macOS.

Constant Summary

Constants included from Dependable

Dependable::RESERVED_TAGS

Instance Attribute Summary collapse

Attributes inherited from Requirement

#cask, #download, #name, #tags

Instance Method Summary collapse

Methods inherited from Requirement

#==, env, #env, #env_proc, expand, #fatal?, #hash, #mktemp, #modify_build_environment, #option_names, prune, prune?, #satisfied?, #satisfied_result_parent, satisfy

Methods included from BuildEnvironment::DSL

#env

Methods included from Dependable

#build?, #option_tags, #optional?, #options, #prune_from_option?, #prune_if_build_and_not_dependent?, #recommended?, #required?, #test?

Constructor Details

#initialize(tags = [], comparator: ">=") ⇒ MacOSRequirement

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MacOSRequirement.


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'Library/Homebrew/requirements/macos_requirement.rb', line 14

def initialize(tags = [], comparator: ">=")
  begin
    @version = if comparator == "==" && tags.first.respond_to?(:map)
      tags.shift.map { |s| MacOS::Version.from_symbol(s) }
    else
      MacOS::Version.from_symbol(tags.shift) unless tags.empty?
    end
  rescue MacOSVersionError => e
    raise if e.version != :mavericks

    odisabled "depends_on :macos => :mavericks"
  end

  @comparator = comparator
  super(tags)
end

Instance Attribute Details

#comparatorObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


12
13
14
# File 'Library/Homebrew/requirements/macos_requirement.rb', line 12

def comparator
  @comparator
end

#versionObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


12
13
14
# File 'Library/Homebrew/requirements/macos_requirement.rb', line 12

def version
  @version
end

Instance Method Details

#display_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


73
74
75
76
77
# File 'Library/Homebrew/requirements/macos_requirement.rb', line 73

def display_s
  return "macOS" unless version_specified?

  "macOS #{@comparator} #{@version}"
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


69
70
71
# File 'Library/Homebrew/requirements/macos_requirement.rb', line 69

def inspect
  "#<#{self.class.name}: version#{@comparator}#{@version.to_s.inspect} #{tags.inspect}>"
end

#message(type: :formula) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'Library/Homebrew/requirements/macos_requirement.rb', line 43

def message(type: :formula)
  return "macOS is required for this software." unless version_specified?

  case @comparator
  when ">="
    "macOS #{@version.pretty_name} or newer is required for this software."
  when "<="
    case type
    when :formula
      <<~EOS
        This formula either does not compile or function as expected on macOS
        versions newer than #{@version.pretty_name} due to an upstream incompatibility.
      EOS
    when :cask
      "This cask does not run on macOS versions newer than #{@version.pretty_name}."
    end
  else
    if @version.respond_to?(:to_ary)
      *versions, last = @version.map(&:pretty_name)
      return "macOS #{versions.join(", ")} or #{last} is required for this software."
    end

    "macOS #{@version.pretty_name} is required for this software."
  end
end

#to_json(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


79
80
81
82
83
84
# File 'Library/Homebrew/requirements/macos_requirement.rb', line 79

def to_json(*args)
  comp = @comparator.to_s
  return { comp => @version.map(&:to_s) }.to_json(*args) if @version.is_a?(Array)

  { comp => [@version.to_s] }.to_json(*args)
end

#version_specified?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

31
32
33
# File 'Library/Homebrew/requirements/macos_requirement.rb', line 31

def version_specified?
  OS.mac? && @version
end