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.


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

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

    odeprecated "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.


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

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.


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

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.


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

def display_s
  return "macOS is required" 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.


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

def inspect
  "#<#{self.class.name}: #{tags.inspect} version#{@comparator}#{@version}>"
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.


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

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

  case @comparator
  when ">="
    "macOS #{@version.pretty_name} or newer is required."
  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."
    end

    "macOS #{@version.pretty_name} is required."
  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.


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

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)

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

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