Class: Cask::Config
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
- 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", 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 ⇒ Hash{Symbol => String, Pathname, Array<String>}
internal
Get the explicit configuration.
Class Method Summary collapse
- .canonicalize(config) ⇒ Hash{Symbol => String, Pathname, Array<String>} private
- .defaults ⇒ Hash{Symbol => String} private
- .from_args(args) ⇒ T.attached_class private
- .from_json(json, ignore_invalid_keys: false) ⇒ T.attached_class private
Instance Method Summary collapse
- #bash_completion ⇒ Pathname private
- #binarydir ⇒ Pathname private
- #default ⇒ Hash{Symbol => String, Pathname, Array<String>} private
- #env ⇒ Hash{Symbol => String, Pathname, Array<String>} private
- #fish_completion ⇒ Pathname private
- #initialize(default: nil, env: nil, explicit: {}, ignore_invalid_keys: false) ⇒ void constructor private
- #languages ⇒ Array<String> private
- #languages=(languages) ⇒ void private
- #manpagedir ⇒ Pathname private
- #merge(other) ⇒ T.self_type private
- #to_json(*options) ⇒ String private
- #zsh_completion ⇒ Pathname private
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.
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 117 def initialize(default: nil, env: nil, explicit: {}, ignore_invalid_keys: false) if default @default = T.let( self.class.canonicalize(self.class.defaults.merge(default)), T.nilable(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]), ) end if env @env = T.let( self.class.canonicalize(env), T.nilable(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]), ) end @explicit = T.let( self.class.canonicalize(explicit), T::Hash[Symbol, T.any(String, Pathname, T::Array[String])], ) if ignore_invalid_keys @env&.delete_if { |key, _| self.class.defaults.keys.exclude?(key) } @explicit.delete_if { |key, _| self.class.defaults.keys.exclude?(key) } return end @env&.assert_valid_keys(*self.class.defaults.keys) @explicit.assert_valid_keys(*self.class.defaults.keys) end |
Instance Attribute Details
#explicit ⇒ Hash{Symbol => String, Pathname, Array<String>}
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.
107 108 109 |
# File 'cask/config.rb', line 107 def explicit @explicit end |
Class Method Details
.canonicalize(config) ⇒ Hash{Symbol => String, Pathname, 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.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'cask/config.rb', line 89 def self.canonicalize(config) config.to_h do |k, v| key = k.to_sym if DEFAULT_DIRS.key?(key) raise TypeError, "Invalid path for default dir #{k}: #{v.inspect}" if v.is_a?(Array) [key, Pathname(v).] else [key, v] end end end |
.defaults ⇒ Hash{Symbol => 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.
37 38 39 40 41 |
# File 'cask/config.rb', line 37 def self.defaults { languages: LazyObject.new { ::OS::Mac.languages }, }.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.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'cask/config.rb', line 44 def self.from_args(args) # FIXME: T.unsafe is a workaround for methods that are only defined when `cask_options` # is invoked on the parser. (These could be captured by a DSL compiler instead.) args = T.unsafe(args) new(explicit: { appdir: args.appdir, keyboard_layoutdir: args.keyboard_layoutdir, colorpickerdir: args.colorpickerdir, prefpanedir: args.prefpanedir, qlplugindir: args.qlplugindir, mdimporterdir: args.mdimporterdir, dictionarydir: args.dictionarydir, fontdir: args.fontdir, servicedir: args.servicedir, input_methoddir: args.input_methoddir, internet_plugindir: args.internet_plugindir, audio_unit_plugindir: args.audio_unit_plugindir, vst_plugindir: args.vst_plugindir, vst3_plugindir: args.vst3_plugindir, screen_saverdir: args.screen_saverdir, languages: args.language, }.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.
69 70 71 72 73 74 75 76 77 78 |
# File 'cask/config.rb', line 69 def self.from_json(json, ignore_invalid_keys: false) config = JSON.parse(json) new( default: config.fetch("default", {}), env: config.fetch("env", {}), explicit: config.fetch("explicit", {}), ignore_invalid_keys:, ) end |
Instance Method Details
#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.
180 181 182 |
# File 'cask/config.rb', line 180 def bash_completion @bash_completion ||= T.let(HOMEBREW_PREFIX/"etc/bash_completion.d", T.nilable(Pathname)) 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.
170 171 172 |
# File 'cask/config.rb', line 170 def binarydir @binarydir ||= T.let(HOMEBREW_PREFIX/"bin", T.nilable(Pathname)) end |
#default ⇒ Hash{Symbol => String, Pathname, 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.
146 147 148 |
# File 'cask/config.rb', line 146 def default @default ||= self.class.canonicalize(self.class.defaults) end |
#env ⇒ Hash{Symbol => String, Pathname, 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.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'cask/config.rb', line 151 def env @env ||= self.class.canonicalize( Homebrew::EnvConfig.cask_opts .select { |arg| arg.include?("=") } .map { |arg| T.cast(arg.split("=", 2), [String, String]) } .map do |(flag, value)| key = flag.sub(/^--/, "") # converts --language flag to :languages config key if key == "language" key = "languages" value = value.split(",") end [key, 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.
190 191 192 |
# File 'cask/config.rb', line 190 def fish_completion @fish_completion ||= T.let(HOMEBREW_PREFIX/"share/fish/vendor_completions.d", T.nilable(Pathname)) 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.
195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'cask/config.rb', line 195 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.
210 211 212 |
# File 'cask/config.rb', line 210 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.
175 176 177 |
# File 'cask/config.rb', line 175 def manpagedir @manpagedir ||= T.let(HOMEBREW_PREFIX/"share/man", T.nilable(Pathname)) 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.
227 228 229 |
# File 'cask/config.rb', line 227 def merge(other) self.class.new(explicit: other.explicit.merge(explicit)) 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.
232 233 234 235 236 237 238 |
# File 'cask/config.rb', line 232 def to_json(*) { default:, env:, explicit:, }.to_json(*) 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.
185 186 187 |
# File 'cask/config.rb', line 185 def zsh_completion @zsh_completion ||= T.let(HOMEBREW_PREFIX/"share/zsh/site-functions", T.nilable(Pathname)) end |