Spec-Zone.ru › Homebrew

Class: Cask::Artifact::Relocated Private

Inherits:
AbstractArtifact
  • Object
  • AbstractArtifact
  • Cask::Artifact::Relocated
show all
Includes:
OS::Linux::Cask::Artifact::Relocated
Defined in:
cask/artifact/relocated.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.

Superclass for all artifacts which have a source and a target location.

Direct Known Subclasses

Moved, Symlinked

Constant Summary

Constants inherited from AbstractArtifact

AbstractArtifact::DirectivesType

Instance Attribute Summary

Attributes inherited from AbstractArtifact

#cask

Class Method Summary collapse

  • .from_args(cask, source_string, target_hash = nil) ⇒ T.attached_class private

Instance Method Summary collapse

  • #initialize(cask, source, **target_hash) ⇒ void constructor private
  • #resolve_target(target, base_dir: config.public_send(self.class.dirmethod)) ⇒ Pathname private
  • #source ⇒ Pathname private
  • #summarize ⇒ String private
  • #target ⇒ Pathname private
  • #to_a ⇒ Array<T.anything> private

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, #to_args

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_upgradable, #pretty_warning

Constructor Details

#initialize(cask, source, **target_hash) ⇒ 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:

  • cask (Cask)
  • source (String, Pathname)
  • target_hash (String, Pathname)


46
47
48
49
50
51
52
53
54
# File 'cask/artifact/relocated.rb', line 46

def initialize(cask, source, **target_hash)
  super

  target = target_hash[:target]
  @source = T.let(nil, T.nilable(Pathname))
  @source_string = T.let(source.to_s, String)
  @target = T.let(nil, T.nilable(Pathname))
  @target_string = T.let(target.to_s, String)
end

Class Method Details

.from_args(cask, source_string, target_hash = 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:

  • cask (Cask)
  • source_string (String, Pathname)
  • target_hash (T.untyped) (defaults to: nil)

Returns:

  • (T.attached_class)


18
19
20
21
22
23
24
25
26
27
28
# File 'cask/artifact/relocated.rb', line 18

def self.from_args(cask, source_string, target_hash = nil)
  if target_hash
    raise CaskInvalidError, cask unless target_hash.respond_to?(:keys)

    target_hash.assert_valid_keys(:target)
  end

  target_hash ||= {}

  new(cask, source_string, **target_hash)
end

Instance Method Details

#resolve_target(target, base_dir: config.public_send(self.class.dirmethod)) ⇒ Pathname

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:

  • target (String, Pathname)
  • base_dir (Pathname, nil) (defaults to: config.public_send(self.class.dirmethod))

Returns:

  • (Pathname)


31
32
33
34
35
36
37
38
39
40
# File 'cask/artifact/relocated.rb', line 31

def resolve_target(target, base_dir: config.public_send(self.class.dirmethod))
  target = Pathname(target)

  if target.relative?
    return target.expand_path if target.descend.first.to_s == "~"
    return base_dir/target if base_dir
  end

  target
end

#source ⇒ Pathname

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:

  • (Pathname)


57
58
59
60
61
62
63
# File 'cask/artifact/relocated.rb', line 57

def source
  @source ||= begin
    base_path = cask.staged_path
    base_path = base_path.join(T.must(cask.url).only_path) if cask.url&.only_path.present?
    base_path.join(@source_string)
  end
end

#summarize ⇒ String

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:

  • (String)


78
79
80
81
# File 'cask/artifact/relocated.rb', line 78

def summarize
  target_string = @target_string.empty? ? "" : " -> #{@target_string}"
  "#{@source_string}#{target_string}"
end

#target ⇒ Pathname

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:

  • (Pathname)


66
67
68
# File 'cask/artifact/relocated.rb', line 66

def target
  @target ||= resolve_target(@target_string.presence || source.basename)
end

#to_a ⇒ Array<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:

  • (Array<T.anything>)


71
72
73
74
75
# File 'cask/artifact/relocated.rb', line 71

def to_a
  [@source_string].tap do |ary|
    ary << { target: @target_string } unless @target_string.empty?
  end
end

© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
https://docs.brew.sh/rubydoc/Cask/Artifact/Relocated.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API