Class: Cask::Config
- Includes:
- Utils::Output::Mixin
- Defined in:
- cask/config.rb,
sorbet/rbi/dsl/cask/config.rbi
Overview
This class is part of an internal API. This class may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Configuration for installing casks.
Constant Summary collapse
- ConfigHash =
This constant is part of an internal API. This constant may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.type_alias { T::Hash[Symbol, T.any(LazyObject, String, Pathname, T::Array[String])] }
- DEFAULT_DIRS =
This constant is part of an internal API. This constant may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.let( { appdir: "/Applications", appimagedir: "~/Applications", keyboard_layoutdir: "/Library/Keyboard Layouts", colorpickerdir: "~/Library/ColorPickers", prefpanedir: "~/Library/PreferencePanes", qlplugindir: "~/Library/QuickLook", mdimporterdir: "~/Library/Spotlight", dictionarydir: "~/Library/Dictionaries", fontdir: "~/Library/Fonts", servicedir: "~/Library/Services", input_methoddir: "~/Library/Input Methods", internet_plugindir: "~/Library/Internet Plug-Ins", audio_unit_plugindir: "~/Library/Audio/Plug-Ins/Components", vst_plugindir: "~/Library/Audio/Plug-Ins/VST", vst3_plugindir: "~/Library/Audio/Plug-Ins/VST3", screen_saverdir: "~/Library/Screen Savers", }.freeze, T::Hash[Symbol, String], )
Instance Attribute Summary collapse
-
#explicit ⇒ ConfigHash
internal
Get the explicit configuration.
Class Method Summary collapse
-
.canonicalize(config) ⇒ ConfigHash
private
runtime recursive evaluation forces the LazyObject to be evaluated.
-
.defaults ⇒ ConfigHash
private
runtime recursive evaluation forces the LazyObject to be evaluated.
- .from_args(args) ⇒ T.attached_class private
- .from_json(json, ignore_invalid_keys: false) ⇒ T.attached_class private
-
.reject_legacy_keys(config) ⇒ ConfigHash?
private
Saved configs can contain hyphenated option names that were never honored when read back, so drop them instead of warning about them or retroactively making them take effect.
Instance Method Summary collapse
- #appdir ⇒ Pathname private
- #appimagedir ⇒ Pathname private
- #audio_unit_plugindir ⇒ Pathname private
- #bash_completion ⇒ Pathname private
- #binarydir ⇒ Pathname private
- #colorpickerdir ⇒ Pathname private
-
#default ⇒ ConfigHash
private
runtime recursive evaluation forces the LazyObject to be evaluated.
- #dictionarydir ⇒ Pathname private
- #env ⇒ ConfigHash private
- #fish_completion ⇒ Pathname private
- #fontdir ⇒ Pathname private
- #initialize(default: nil, env: nil, explicit: {}, ignore_invalid_keys: false) ⇒ void constructor private
- #input_methoddir ⇒ Pathname private
- #internet_plugindir ⇒ Pathname private
- #keyboard_layoutdir ⇒ Pathname private
- #languages ⇒ Array<String> private
- #languages=(languages) ⇒ void private
- #manpagedir ⇒ Pathname private
- #mdimporterdir ⇒ Pathname private
- #merge(other) ⇒ T.self_type private
- #prefpanedir ⇒ Pathname private
- #qlplugindir ⇒ Pathname private
- #screen_saverdir ⇒ Pathname private
- #servicedir ⇒ Pathname private
- #to_json(*options) ⇒ String private
- #vst3_plugindir ⇒ Pathname private
- #vst_plugindir ⇒ Pathname private
- #zsh_completion ⇒ Pathname 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_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
#initialize(default: nil, env: nil, explicit: {}, ignore_invalid_keys: false) ⇒ 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.
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 137 138 139 140 141 142 143 |
# File 'cask/config.rb', line 111 def initialize(default: nil, env: nil, explicit: {}, ignore_invalid_keys: false) # Define all instance variables in a consistent order so every instance # shares one object shape, avoiding Ruby's shape-variation warning. @default = T.let( default ? self.class.canonicalize(self.class.defaults.merge(default)) : nil, T.nilable(ConfigHash), ) @env = T.let( env ? self.class.canonicalize(env) : nil, T.nilable(ConfigHash), ) @explicit = T.let( self.class.canonicalize(explicit), ConfigHash, ) @binarydir = T.let(nil, T.nilable(Pathname)) @manpagedir = T.let(nil, T.nilable(Pathname)) @bash_completion = T.let(nil, T.nilable(Pathname)) @zsh_completion = T.let(nil, T.nilable(Pathname)) @fish_completion = T.let(nil, T.nilable(Pathname)) if ignore_invalid_keys && (unknown_keys = ((Array(@env&.keys) + @explicit.keys).uniq - self.class.defaults.keys).presence) opoo "Ignoring unknown cask configuration keys: #{unknown_keys.inspect}" @env&.delete_if { |key, _| unknown_keys.include?(key) } @explicit.delete_if { |key, _| unknown_keys.include?(key) } return end ::Utils::Data.assert_valid_keys(@env, *self.class.defaults.keys) if @env ::Utils::Data.assert_valid_keys(@explicit, *self.class.defaults.keys) end |
Instance Attribute Details
#explicit ⇒ ConfigHash
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Get the explicit configuration.
101 102 103 |
# File 'cask/config.rb', line 101 def explicit @explicit end |
Class Method Details
.canonicalize(config) ⇒ ConfigHash
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.
runtime recursive evaluation forces the LazyObject to be evaluated
85 86 87 88 89 90 91 92 93 94 95 |
# File 'cask/config.rb', line 85 def self.canonicalize(config) config.to_h do |k, v| if DEFAULT_DIRS.key?(k) raise TypeError, "Invalid path for default dir #{k}: #{v.inspect}" if v.is_a?(Array) [k, Pathname(v.to_s).] else [k, v] end end end |
.defaults ⇒ ConfigHash
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.
runtime recursive evaluation forces the LazyObject to be evaluated
45 46 47 48 49 |
# File 'cask/config.rb', line 45 def self.defaults { languages: T.let([], T::Array[String]), }.merge(DEFAULT_DIRS).freeze end |
.from_args(args) ⇒ T.attached_class
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.
52 53 54 55 56 57 58 59 |
# File 'cask/config.rb', line 52 def self.from_args(args) # The option methods are only defined on `args` when `cask_options` is invoked on the parser. explicit = [*DEFAULT_DIRS.keys, :language].to_h do |option| [option, (args.public_send(option) if args.respond_to?(option))] end explicit[:languages] = explicit.delete(:language) new(explicit: explicit.compact) end |
.from_json(json, ignore_invalid_keys: false) ⇒ T.attached_class
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.
62 63 64 65 66 67 68 69 70 71 |
# File 'cask/config.rb', line 62 def self.from_json(json, ignore_invalid_keys: false) config = JSON.parse(json, symbolize_names: true) new( default: reject_legacy_keys(config.fetch(:default, {})), env: reject_legacy_keys(config.fetch(:env, {})), explicit: reject_legacy_keys(config.fetch(:explicit, {})) || {}, ignore_invalid_keys:, ) end |
.reject_legacy_keys(config) ⇒ ConfigHash?
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.
Saved configs can contain hyphenated option names that were never honored when read back, so drop them instead of warning about them or retroactively making them take effect.
76 77 78 79 80 81 |
# File 'cask/config.rb', line 76 def self.reject_legacy_keys(config) return if config.nil? valid_keys = defaults config.reject { |key, _| key.to_s.include?("-") && valid_keys.key?(key.to_s.tr("-", "_").to_sym) } end |
Instance Method Details
#appdir ⇒ 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.
11 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 11 def appdir; end |
#appimagedir ⇒ 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.
14 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 14 def appimagedir; end |
#audio_unit_plugindir ⇒ 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.
17 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 17 def audio_unit_plugindir; end |
#bash_completion ⇒ 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.
182 183 184 |
# File 'cask/config.rb', line 182 def bash_completion @bash_completion ||= HOMEBREW_PREFIX/"etc/bash_completion.d" end |
#binarydir ⇒ 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.
172 173 174 |
# File 'cask/config.rb', line 172 def binarydir @binarydir ||= HOMEBREW_PREFIX/"bin" end |
#colorpickerdir ⇒ 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.
20 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 20 def colorpickerdir; end |
#default ⇒ ConfigHash
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.
runtime recursive evaluation forces the LazyObject to be evaluated
147 148 149 |
# File 'cask/config.rb', line 147 def default @default ||= self.class.canonicalize(self.class.defaults) end |
#dictionarydir ⇒ 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.
23 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 23 def dictionarydir; end |
#env ⇒ ConfigHash
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.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'cask/config.rb', line 152 def env @env ||= self.class.canonicalize( Homebrew::EnvConfig.cask_opts .select { |arg| arg.include?("=") } .map { |arg| T.cast(arg.split("=", 2), [String, String]) } .to_h do |(flag, value)| # command-line flags are hyphenated (e.g. --input-methoddir) but config keys use underscores key = flag.sub(/^--/, "").tr("-", "_") # converts --language flag to :languages config key if key == "language" key = "languages" value = value.split(",") end [key.to_sym, value] end, ) end |
#fish_completion ⇒ 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.
192 193 194 |
# File 'cask/config.rb', line 192 def fish_completion @fish_completion ||= HOMEBREW_PREFIX/"share/fish/vendor_completions.d" end |
#fontdir ⇒ 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.
26 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 26 def fontdir; end |
#input_methoddir ⇒ 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.
29 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 29 def input_methoddir; end |
#internet_plugindir ⇒ 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.
32 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 32 def internet_plugindir; end |
#keyboard_layoutdir ⇒ 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.
35 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 35 def keyboard_layoutdir; end |
#languages ⇒ Array<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.
197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'cask/config.rb', line 197 def languages [ *explicit.fetch(:languages, []), *env.fetch(:languages, []), *default.fetch(:languages, []), ].uniq.select do |lang| # Ensure all languages are valid. Locale.parse(lang) true rescue Locale::ParserError false end end |
#languages=(languages) ⇒ 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.
212 213 214 |
# File 'cask/config.rb', line 212 def languages=(languages) explicit[:languages] = languages end |
#manpagedir ⇒ 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.
177 178 179 |
# File 'cask/config.rb', line 177 def manpagedir @manpagedir ||= HOMEBREW_PREFIX/"share/man" end |
#mdimporterdir ⇒ 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.
41 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 41 def mdimporterdir; end |
#merge(other) ⇒ T.self_type
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.
229 230 231 |
# File 'cask/config.rb', line 229 def merge(other) self.class.new(explicit: other.explicit.merge(explicit)) end |
#prefpanedir ⇒ 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.
44 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 44 def prefpanedir; end |
#qlplugindir ⇒ 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.
47 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 47 def qlplugindir; end |
#screen_saverdir ⇒ 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.
50 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 50 def screen_saverdir; end |
#servicedir ⇒ 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.
53 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 53 def servicedir; end |
#to_json(*options) ⇒ 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.
234 235 236 237 238 239 240 |
# File 'cask/config.rb', line 234 def to_json(*) { default:, env:, explicit:, }.to_json(*) end |
#vst3_plugindir ⇒ 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.
56 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 56 def vst3_plugindir; end |
#vst_plugindir ⇒ 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.
59 |
# File 'sorbet/rbi/dsl/cask/config.rbi', line 59 def vst_plugindir; end |
#zsh_completion ⇒ 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.
187 188 189 |
# File 'cask/config.rb', line 187 def zsh_completion @zsh_completion ||= HOMEBREW_PREFIX/"share/zsh/site-functions" end |