Class: Cask::Artifact::AbstractArtifact Abstract Private
- Extended by:
- T::Helpers, Utils::Output::Mixin
- Includes:
- Comparable, Utils::Output::Mixin
- 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.
It cannot be directly instantiated. Subclasses must implement the abstract methods below.
Abstract superclass for all artifacts.
Direct Known Subclasses
AbstractFlightBlock, AbstractUninstall, Installer, Pkg, Relocated, StageOnly
Constant Summary collapse
- DirectivesType =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.anything or the union of all possible argument types would be better choice, but it's convenient to be able to invoke
.inspect,.to_s, etc. without the overhead of type guards. T.type_alias { Object }
Instance Attribute Summary collapse
- #cask ⇒ Cask readonly private
Class Method Summary collapse
- .dirmethod ⇒ Symbol private
- .dsl_key ⇒ Symbol private
- .english_article ⇒ String private
- .english_name ⇒ String private
- .read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil) ⇒ Array<([String, nil], Hash{Symbol => T.untyped})> private
Instance Method Summary collapse
- #config ⇒ Config private
- #initialize(cask, *dsl_args) ⇒ void constructor private
- #sort_order ⇒ Hash{T.class_of(AbstractArtifact) => Integer} private
- #staged_path_join_executable(path) ⇒ Pathname private
- #summarize ⇒ String abstract private
- #to_args ⇒ Array<T.anything> private
Methods included from Utils::Output::Mixin
odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, pretty_deprecated, pretty_disabled, pretty_duration, pretty_installed, pretty_outdated, pretty_uninstalled
Constructor Details
#initialize(cask, *dsl_args) ⇒ 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.
171 172 173 174 175 176 177 178 179 |
# File 'cask/artifact/abstract_artifact.rb', line 171 def initialize(cask, *dsl_args) @cask = cask @dirmethod = T.let(nil, T.nilable(Symbol)) @dsl_args = T.let(dsl_args.deep_dup, T::Array[T.anything]) @dsl_key = T.let(nil, T.nilable(Symbol)) @english_article = T.let(nil, T.nilable(String)) @english_name = T.let(nil, T.nilable(String)) @sort_order = T.let(nil, T.nilable(T::Hash[T.class_of(AbstractArtifact), Integer])) end |
Instance Attribute Details
#cask ⇒ Cask (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.
168 169 170 |
# File 'cask/artifact/abstract_artifact.rb', line 168 def cask @cask end |
Class Method Details
.dirmethod ⇒ Symbol
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.
40 41 42 |
# File 'cask/artifact/abstract_artifact.rb', line 40 def self.dirmethod @dirmethod ||= T.let(:"#{dsl_key}dir", T.nilable(Symbol)) end |
.dsl_key ⇒ Symbol
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.
34 35 36 37 |
# File 'cask/artifact/abstract_artifact.rb', line 34 def self.dsl_key @dsl_key ||= T.let(T.must(name).sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase.to_sym, T.nilable(Symbol)) end |
.english_article ⇒ 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.
29 30 31 |
# File 'cask/artifact/abstract_artifact.rb', line 29 def self.english_article @english_article ||= T.let(/^[aeiou]/i.match?(english_name) ? "an" : "a", T.nilable(String)) end |
.english_name ⇒ 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.
24 25 26 |
# File 'cask/artifact/abstract_artifact.rb', line 24 def self.english_name @english_name ||= T.let(T.must(name).sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1 \2'), T.nilable(String)) end |
.read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil) ⇒ Array<([String, nil], Hash{Symbol => T.untyped})>
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 sort of logic would make more sense in dsl.rb, or a constructor called from dsl.rb, so long as that isn't slow.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'cask/artifact/abstract_artifact.rb', line 130 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 arguments = case arguments when String then { executable: arguments } # backward-compatible string value when Hash then arguments.dup # Avoid mutating the original argument else odie "Unsupported arguments type #{arguments.class}" 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
#config ⇒ Config
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.
182 183 184 |
# File 'cask/artifact/abstract_artifact.rb', line 182 def config cask.config end |
#sort_order ⇒ Hash{T.class_of(AbstractArtifact) => Integer}
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.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'cask/artifact/abstract_artifact.rb', line 68 def sort_order @sort_order ||= T.let( [ PreflightBlock, # The `uninstall` stanza should be run first, as it may # depend on other artifacts still being installed. Uninstall, Installer, # `pkg` should be run before `binary`, so # targets are created prior to linking. # `pkg` should be run before `app`, since an `app` could # contain a nested installer (e.g. `wireshark`). Pkg, [ App, Suite, Artifact, Colorpicker, Prefpane, Qlplugin, Mdimporter, Dictionary, Font, Service, InputMethod, InternetPlugin, KeyboardLayout, AudioUnitPlugin, VstPlugin, Vst3Plugin, ScreenSaver, ], Binary, Manpage, PostflightBlock, Zap, ].each_with_index.flat_map { |classes, i| Array(classes).map { |c| [c, i] } }.to_h, T.nilable(T::Hash[T.class_of(AbstractArtifact), Integer]), ) end |
#staged_path_join_executable(path) ⇒ 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.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'cask/artifact/abstract_artifact.rb', line 48 def staged_path_join_executable(path) path = Pathname(path) path = 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 |
#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.
45 |
# File 'cask/artifact/abstract_artifact.rb', line 45 def summarize; end |
#to_args ⇒ 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.
192 193 194 |
# File 'cask/artifact/abstract_artifact.rb', line 192 def to_args @dsl_args.compact_blank end |