Class: Cask::Artifact::GeneratedScript Private

Inherits:
AbstractArtifact show all
Defined in:
cask/artifact/generated_script.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 generated_script stanza.

Constant Summary

Constants inherited from AbstractArtifact

AbstractArtifact::DirectivesType

Instance Attribute Summary

Attributes inherited from AbstractArtifact

#cask

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractArtifact

#cask_sandbox, #cask_sandbox_command, #config, dirmethod, dsl_key, english_article, english_name, read_script_arguments, #run_cask_sandbox, #sort_order, #staged_path_join_executable

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Constructor Details

#initialize(cask, path, content:) ⇒ void

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.

Parameters:

Raises:



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'cask/artifact/generated_script.rb', line 24

def initialize(cask, path, content:)
  raise CaskInvalidError.new(cask, "'generated_script' requires content") if content.blank?

  super(cask)
  path = Pathname(path)
  if path.absolute? || path.each_filename.any?("..")
    raise CaskInvalidError.new(cask, "'generated_script' requires a path within the staged cask")
  end

  @path = T.let(cask.staged_path/path, Pathname)
  @path_string = T.let(path.to_s, String)
  @content = content
end

Class Method Details

.from_args(cask, path, options = nil) ⇒ T.attached_class

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.

Parameters:

Returns:

  • (T.attached_class)


17
18
19
20
21
# File 'cask/artifact/generated_script.rb', line 17

def self.from_args(cask, path, options = nil)
  options ||= {}
  options.assert_valid_keys(:content)
  new(cask, path, **options)
end

Instance Method Details

#install_phase(**_options) ⇒ void

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.

This method returns an undefined value.

Parameters:

  • _options (T.anything)


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'cask/artifact/generated_script.rb', line 39

def install_phase(**_options)
  @path.ascend do |path|
    break if path == cask.staged_path

    raise CaskInvalidError.new(cask, "'generated_script' path contains a symlink") if path.symlink?
  end

  @path.dirname.mkpath
  File.open(@path, File::WRONLY | File::CREAT | File::TRUNC | File::NOFOLLOW) do |file|
    file.write(@content)
    file.chmod(0755)
  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:



59
# File 'cask/artifact/generated_script.rb', line 59

def summarize = @path_string

#to_argsArray<T.anything>

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:



54
55
56
# File 'cask/artifact/generated_script.rb', line 54

def to_args
  [@path_string, { content: @content }]
end