Class: KegOnlyReason

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
Library/Homebrew/formula_support.rb,
Library/Homebrew/extend/os/mac/formula_support.rb

Overview

typed: strict frozen_string_literal: true

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reason, explanation) ⇒ KegOnlyReason

Returns a new instance of KegOnlyReason.


12
13
14
15
# File 'Library/Homebrew/formula_support.rb', line 12

def initialize(reason, explanation)
  @reason = reason
  @explanation = explanation
end

Instance Attribute Details

#reasonObject (readonly)

Returns the value of attribute reason


10
11
12
# File 'Library/Homebrew/formula_support.rb', line 10

def reason
  @reason
end

Instance Method Details

#applicable?Boolean

Returns:

  • (Boolean)

33
34
35
36
37
# File 'Library/Homebrew/formula_support.rb', line 33

def applicable?
  # macOS reasons aren't applicable on other OSs
  # (see extend/os/mac/formula_support for override on macOS)
  !by_macos?
end

#by_macos?Boolean

Returns:

  • (Boolean)

29
30
31
# File 'Library/Homebrew/formula_support.rb', line 29

def by_macos?
  provided_by_macos? || shadowed_by_macos?
end

#provided_by_macos?Boolean

Returns:

  • (Boolean)

21
22
23
# File 'Library/Homebrew/formula_support.rb', line 21

def provided_by_macos?
  @reason == :provided_by_macos
end

#shadowed_by_macos?Boolean

Returns:

  • (Boolean)

25
26
27
# File 'Library/Homebrew/formula_support.rb', line 25

def shadowed_by_macos?
  @reason == :shadowed_by_macos
end

#to_sObject


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'Library/Homebrew/formula_support.rb', line 39

def to_s
  return @explanation unless @explanation.empty?

  if versioned_formula?
    <<~EOS
      this is an alternate version of another formula
    EOS
  elsif provided_by_macos?
    <<~EOS
      macOS already provides this software and installing another version in
      parallel can cause all kinds of trouble
    EOS
  elsif shadowed_by_macos?
    <<~EOS
      macOS provides similar software and installing this software in
      parallel can cause all kinds of trouble
    EOS
  else
    @reason
  end.strip
end

#versioned_formula?Boolean

Returns:

  • (Boolean)

17
18
19
# File 'Library/Homebrew/formula_support.rb', line 17

def versioned_formula?
  @reason == :versioned_formula
end