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, AbstractInstallSteps, AbstractUninstall, GeneratedCompletion, 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
- #cask_sandbox ⇒ Sandbox? private
- #cask_sandbox_command(env, args, home:) ⇒ Array<String, Pathname> private
- #config ⇒ Config private
- #initialize(cask, *dsl_args) ⇒ void constructor private
- #run_cask_sandbox(sandbox, args, input: []) ⇒ void 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
issue_reporting_message, odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, opoo_without_github_actions_annotation, pretty_deprecated, pretty_disabled, pretty_duration, pretty_install_status, pretty_installed, pretty_uninstalled, pretty_unmarked, pretty_upgradable, pretty_warning
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.
183 184 185 186 187 188 189 190 191 |
# File 'cask/artifact/abstract_artifact.rb', line 183 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.
180 181 182 |
# File 'cask/artifact/abstract_artifact.rb', line 180 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.
43 44 45 |
# File 'cask/artifact/abstract_artifact.rb', line 43 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.
37 38 39 40 |
# File 'cask/artifact/abstract_artifact.rb', line 37 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.
32 33 34 |
# File 'cask/artifact/abstract_artifact.rb', line 32 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.
27 28 29 |
# File 'cask/artifact/abstract_artifact.rb', line 27 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.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'cask/artifact/abstract_artifact.rb', line 142 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
#cask_sandbox ⇒ Sandbox?
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.
199 200 201 202 203 204 205 206 207 208 209 |
# File 'cask/artifact/abstract_artifact.rb', line 199 def cask_sandbox Sandbox.ensure_sandbox_installed! return unless Sandbox.available? Sandbox.new.tap do |sandbox| sandbox.allow_read(path: cask.staged_path, type: :subpath) sandbox.allow_write_temp_and_cache sandbox.deny_read_home sandbox.deny_all_network end end |
#cask_sandbox_command(env, args, home:) ⇒ Array<String, 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.
218 219 220 221 |
# File 'cask/artifact/abstract_artifact.rb', line 218 def cask_sandbox_command(env, args, home:) env = { "HOME" => home }.merge(env) ["/usr/bin/env", *env.map { |key, value| "#{key}=#{value}" }, *args] end |
#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.
194 195 196 |
# File 'cask/artifact/abstract_artifact.rb', line 194 def config cask.config end |
#run_cask_sandbox(sandbox, args, input: []) ⇒ 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.
This method returns an undefined value.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'cask/artifact/abstract_artifact.rb', line 230 def run_cask_sandbox(sandbox, args, input: []) return sandbox.run(*args) if Array(input).empty? Tempfile.create("homebrew-cask-script-input", HOMEBREW_TEMP) do |input_file| input_file.write(Array(input).join) input_file.close sandbox.allow_read(path: input_file.path) sandbox.run( "/bin/sh", "-c", "input=$1; shift; exec \"$@\" < \"$input\"", "sh", input_file.path, *args, ) end 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.
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 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'cask/artifact/abstract_artifact.rb', line 71 def sort_order @sort_order ||= T.let( [ PreflightBlock, PreflightSteps, UninstallPreflightSteps, # 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, [ BashCompletion, FishCompletion, ZshCompletion, ], PostflightSteps, UninstallPostflightSteps, 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'cask/artifact/abstract_artifact.rb', line 51 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.
48 |
# File 'cask/artifact/abstract_artifact.rb', line 48 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.
254 255 256 |
# File 'cask/artifact/abstract_artifact.rb', line 254 def to_args @dsl_args.compact_blank end |