Class: Hbc::Artifact::Relocated

Inherits:
AbstractArtifact show all
Defined in:
Library/Homebrew/cask/lib/hbc/artifact/relocated.rb

Direct Known Subclasses

Moved, Symlinked

Instance Attribute Summary collapse

Attributes inherited from AbstractArtifact

#cask, #config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractArtifact

#<=>, dirmethod, dsl_key, english_article, english_name, read_script_arguments, #to_s

Methods included from Predicable

#attr_predicate

Constructor Details

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

Returns a new instance of Relocated



27
28
29
30
31
32
33
34
35
36
# File 'Library/Homebrew/cask/lib/hbc/artifact/relocated.rb', line 27

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)

Returns the value of attribute source



25
26
27
# File 'Library/Homebrew/cask/lib/hbc/artifact/relocated.rb', line 25

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target



25
26
27
# File 'Library/Homebrew/cask/lib/hbc/artifact/relocated.rb', line 25

def target
  @target
end

Class Method Details

.from_args(cask, *args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'Library/Homebrew/cask/lib/hbc/artifact/relocated.rb', line 8

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

  if target_hash
    raise CaskInvalidError unless target_hash.respond_to?(:keys)
    target_hash.extend(HashValidator).assert_valid_keys(:target)
  end

  target_hash ||= {}

  new(cask, source_string, **target_hash)
end

Instance Method Details

#resolve_target(target) ⇒ Object



21
22
23
# File 'Library/Homebrew/cask/lib/hbc/artifact/relocated.rb', line 21

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

#summarizeObject



44
45
46
47
# File 'Library/Homebrew/cask/lib/hbc/artifact/relocated.rb', line 44

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

#to_aObject



38
39
40
41
42
# File 'Library/Homebrew/cask/lib/hbc/artifact/relocated.rb', line 38

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