Class: Cask::Artifact::Relocated Private

Inherits:
AbstractArtifact show all
Defined in:
Library/Homebrew/cask/artifact/relocated.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.

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

Direct Known Subclasses

Moved, Symlinked

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_s

Methods included from Predicable

#attr_predicate

Constructor Details

#initialize(cask, source, target: nil) ⇒ Relocated

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 Relocated.


35
36
37
38
39
40
41
42
43
44
# File 'Library/Homebrew/cask/artifact/relocated.rb', line 35

def initialize(cask, source, target: nil)
  super(cask)

  @source_string = source.to_s
  @target_string = target.to_s
  source = cask.staged_path.join(source)
  @source = source
  target ||= source.basename
  @target = resolve_target(target)
end

Instance Attribute Details

#sourceObject (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.


33
34
35
# File 'Library/Homebrew/cask/artifact/relocated.rb', line 33

def source
  @source
end

#targetObject (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.


33
34
35
# File 'Library/Homebrew/cask/artifact/relocated.rb', line 33

def target
  @target
end

Class Method Details

.from_args(cask, *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.


15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'Library/Homebrew/cask/artifact/relocated.rb', line 15

def self.from_args(cask, *args)
  source_string, target_hash = args

  if target_hash
    raise CaskInvalidError 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) ⇒ 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.


29
30
31
# File 'Library/Homebrew/cask/artifact/relocated.rb', line 29

def resolve_target(target)
  config.public_send(self.class.dirmethod).join(target)
end

#summarizeObject

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.


52
53
54
55
# File 'Library/Homebrew/cask/artifact/relocated.rb', line 52

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

#to_aObject

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.


46
47
48
49
50
# File 'Library/Homebrew/cask/artifact/relocated.rb', line 46

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