Class: Cask::Artifact::AbstractArtifact Abstract Private

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers
Includes:
Comparable
Defined in:
cask/artifact/abstract_artifact.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.

This class is abstract.

It cannot be directly instantiated. Subclasses must implement the abstract methods below.

Abstract superclass for all artifacts.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cask, *dsl_args) ⇒ AbstractArtifact

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 a new instance of AbstractArtifact.



140
141
142
143
# File 'cask/artifact/abstract_artifact.rb', line 140

def initialize(cask, *dsl_args)
  @cask = cask
  @dsl_args = dsl_args.deep_dup
end

Instance Attribute Details

#caskObject (readonly)

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.



138
139
140
# File 'cask/artifact/abstract_artifact.rb', line 138

def cask
  @cask
end

Class Method Details

.dirmethodObject

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.



28
29
30
# File 'cask/artifact/abstract_artifact.rb', line 28

def self.dirmethod
  @dirmethod ||= :"#{dsl_key}dir"
end

.dsl_keyObject

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.



24
25
26
# File 'cask/artifact/abstract_artifact.rb', line 24

def self.dsl_key
  @dsl_key ||= T.must(name).sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase.to_sym
end

.english_articleObject

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.



20
21
22
# File 'cask/artifact/abstract_artifact.rb', line 20

def self.english_article
  @english_article ||= /^[aeiou]/i.match?(english_name) ? "an" : "a"
end

.english_nameObject

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.



16
17
18
# File 'cask/artifact/abstract_artifact.rb', line 16

def self.english_name
  @english_name ||= T.must(name).sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1 \2')
end

.read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil) ⇒ Object

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.

TODO:

this sort of logic would make more sense in dsl.rb, or a constructor called from dsl.rb, so long as that isn't slow.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'cask/artifact/abstract_artifact.rb', line 99

def self.read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil)
  # TODO: when stanza names are harmonized with class names,
  #       stanza may not be needed as an explicit argument
  description = key ? "#{stanza} #{key.inspect}" : stanza.to_s

  # backward-compatible string value
  arguments = if arguments.is_a?(String)
    { executable: arguments }
  else
    # Avoid mutating the original argument
    arguments.dup
  end

  # key sanity
  permitted_keys = [:args, :input, :executable, :must_succeed, :sudo, :print_stdout, :print_stderr]
  unknown_keys = arguments.keys - permitted_keys
  unless unknown_keys.empty?
    opoo "Unknown arguments to #{description} -- " \
         "#{unknown_keys.inspect} (ignored). Running " \
         "`brew update; brew cleanup` will likely fix it."
  end
  arguments.select! { |k| permitted_keys.include?(k) }

  # key warnings
  override_keys = override_arguments.keys
  ignored_keys = arguments.keys & override_keys
  unless ignored_keys.empty?
    onoe "Some arguments to #{description} will be ignored -- :#{unknown_keys.inspect} (overridden)."
  end

  # extract executable
  executable = arguments.key?(:executable) ? arguments.delete(:executable) : nil

  arguments = default_arguments.merge arguments
  arguments.merge! override_arguments

  [executable, arguments]
end

Instance Method Details

#configObject

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.



145
146
147
# File 'cask/artifact/abstract_artifact.rb', line 145

def config
  cask.config
end

#staged_path_join_executable(path) ⇒ Object

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.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'cask/artifact/abstract_artifact.rb', line 35

def staged_path_join_executable(path)
  path = Pathname(path)
  path = path.expand_path if path.to_s.start_with?("~")

  absolute_path = if path.absolute?
    path
  else
    cask.staged_path.join(path)
  end

  FileUtils.chmod "+x", absolute_path if absolute_path.exist? && !absolute_path.executable?

  if absolute_path.exist?
    absolute_path
  else
    path
  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.

This method is abstract.

Returns:



33
# File 'cask/artifact/abstract_artifact.rb', line 33

def summarize; end

#to_argsObject

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.



154
155
156
# File 'cask/artifact/abstract_artifact.rb', line 154

def to_args
  @dsl_args.compact_blank
end