Class: Hbc::Artifact::Installer

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

Defined Under Namespace

Modules: ManualInstaller, ScriptInstaller

Constant Summary collapse

VALID_KEYS =
Set.new [
  :manual,
  :script,
]

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, **args) ⇒ Installer

Returns a new instance of Installer

Raises:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'Library/Homebrew/cask/lib/hbc/artifact/installer.rb', line 53

def initialize(cask, **args)
  super(cask)

  if args.key?(:manual)
    @path = cask.staged_path.join(args[:manual])
    @args = []
    extend(ManualInstaller)
    return
  end

  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)
  @path = path.absolute? ? path : cask.staged_path.join(path)
  extend(ScriptInstaller)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args



51
52
53
# File 'Library/Homebrew/cask/lib/hbc/artifact/installer.rb', line 51

def args
  @args
end

#pathObject (readonly)

Returns the value of attribute path



51
52
53
# File 'Library/Homebrew/cask/lib/hbc/artifact/installer.rb', line 51

def path
  @path
end

Class Method Details

.from_args(cask, **args) ⇒ Object

Raises:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'Library/Homebrew/cask/lib/hbc/artifact/installer.rb', line 30

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

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

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

Instance Method Details

#summarizeObject



73
74
75
# File 'Library/Homebrew/cask/lib/hbc/artifact/installer.rb', line 73

def summarize
  path.relative_path_from(cask.staged_path).to_s
end

#to_hObject



77
78
79
80
81
# File 'Library/Homebrew/cask/lib/hbc/artifact/installer.rb', line 77

def to_h
  { path: path.relative_path_from(cask.staged_path).to_s }.tap do |h|
    h[:args] = args unless is_a?(ManualInstaller)
  end
end