Class: Cask::Artifact::Installer Private

Inherits:
AbstractArtifact show all
Defined in:
cask/artifact/installer.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Artifact corresponding to the installer stanza.

Constant Summary collapse

VALID_KEYS =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

Set.new([
  :manual,
  :script,
]).freeze

Instance Attribute Summary collapse

Attributes inherited from AbstractArtifact

#cask

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractArtifact

#config, dirmethod, dsl_key, english_article, english_name, read_script_arguments, #staged_path_join_executable, #to_args

Constructor Details

#initialize(cask, **args) ⇒ Installer

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns a new instance of Installer.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'cask/artifact/installer.rb', line 67

def initialize(cask, **args)
  super

  if args.key?(:manual)
    @path = Pathname(args[:manual])
    @args = []
    @manual_install = true
  else
    path, @args = self.class.read_script_arguments(
      args[:script], self.class.dsl_key.to_s, { must_succeed: true, sudo: false }, print_stdout: true
    )
    raise CaskInvalidError.new(cask, "#{self.class.dsl_key} missing executable") if path.nil?

    @path = Pathname(path)
    @manual_install = false
  end
end

Instance Attribute Details

#argsObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



62
63
64
# File 'cask/artifact/installer.rb', line 62

def args
  @args
end

#manual_installBoolean (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


65
66
67
# File 'cask/artifact/installer.rb', line 65

def manual_install
  @manual_install
end

#pathObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



62
63
64
# File 'cask/artifact/installer.rb', line 62

def path
  @path
end

Class Method Details

.from_args(cask, **args) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'cask/artifact/installer.rb', line 38

def self.from_args(cask, **args)
  raise CaskInvalidError.new(cask, "'installer' stanza requires an argument.") if args.empty?

  if args.key?(:script) && !args[:script].respond_to?(:key?)
    if args.key?(:executable)
      raise CaskInvalidError.new(cask, "'installer' stanza gave arguments for both :script and :executable.")
    end

    args[:executable] = args[:script]
    args.delete(:script)
    args = { script: args }
  end

  if args.keys.count != 1
    raise CaskInvalidError.new(
      cask,
      "invalid 'installer' stanza: Only one of #{VALID_KEYS.inspect} is permitted.",
    )
  end

  args.assert_valid_keys(*VALID_KEYS)
  new(cask, **args)
end

Instance Method Details

#install_phase(command: nil, **_) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'cask/artifact/installer.rb', line 16

def install_phase(command: nil, **_)
  if manual_install
    puts <<~EOS
      Cask #{cask} only provides a manual installer. To run it and complete the installation:
        open #{cask.staged_path.join(path).to_s.shellescape}
    EOS
  else
    ohai "Running #{self.class.dsl_key} script '#{path}'"

    executable_path = staged_path_join_executable(path)

    command.run!(
      executable_path,
      **args,
      env:       { "PATH" => PATH.new(
        HOMEBREW_PREFIX/"bin", HOMEBREW_PREFIX/"sbin", ENV.fetch("PATH")
      ) },
      reset_uid: true,
    )
  end
end

#summarizeString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



86
# File 'cask/artifact/installer.rb', line 86

def summarize = path.to_s

#to_hObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



88
89
90
91
92
# File 'cask/artifact/installer.rb', line 88

def to_h
  { path: }.tap do |h|
    h[:args] = args unless manual_install
  end
end