Class: Cask::Config Private
- Inherits:
-
Object
- Object
- Cask::Config
- Defined in:
- Library/Homebrew/cask/config.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Configuration for installing casks.
Constant Summary collapse
- DEFAULT_DIRS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ appdir: "/Applications", 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
Instance Attribute Summary collapse
- #explicit ⇒ Object private
Class Method Summary collapse
- .canonicalize(config) ⇒ Object private
- .defaults ⇒ Object private
- .from_args(args) ⇒ Object private
- .from_json(json) ⇒ Object private
Instance Method Summary collapse
- #binarydir ⇒ Object private
- #default ⇒ Object private
- #env ⇒ Object private
-
#initialize(default: nil, env: nil, explicit: {}) ⇒ Config
constructor
private
A new instance of Config.
- #languages ⇒ Object private
- #languages=(languages) ⇒ Object private
- #manpagedir ⇒ Object private
- #merge(other) ⇒ Object private
- #to_json(*args) ⇒ Object private
Constructor Details
#initialize(default: nil, env: nil, explicit: {}) ⇒ Config
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Config.
88 89 90 91 92 93 94 95 |
# File 'Library/Homebrew/cask/config.rb', line 88 def initialize(default: nil, env: nil, explicit: {}) @default = self.class.canonicalize(self.class.defaults.merge(default)) if default @env = self.class.canonicalize(env) if env @explicit = self.class.canonicalize(explicit) @env&.assert_valid_keys!(*self.class.defaults.keys) @explicit.assert_valid_keys!(*self.class.defaults.keys) end |
Instance Attribute Details
#explicit ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 |
# File 'Library/Homebrew/cask/config.rb', line 86 def explicit @explicit end |
Class Method Details
.canonicalize(config) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
74 75 76 77 78 79 80 81 82 83 84 |
# File 'Library/Homebrew/cask/config.rb', line 74 def self.canonicalize(config) config.map do |k, v| key = k.to_sym if DEFAULT_DIRS.key?(key) [key, Pathname(v).] else [key, v] end end.to_h end |
.defaults ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 37 38 |
# File 'Library/Homebrew/cask/config.rb', line 34 def self.defaults { languages: LazyObject.new { MacOS.languages }, }.merge(DEFAULT_DIRS).freeze end |
.from_args(args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'Library/Homebrew/cask/config.rb', line 40 def self.from_args(args) new(explicit: { appdir: args.appdir, 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'Library/Homebrew/cask/config.rb', line 60 def self.from_json(json) config = begin JSON.parse(json) rescue JSON::ParserError => e raise e, "Cannot parse #{path}: #{e}", e.backtrace end new( default: config.fetch("default", {}), env: config.fetch("env", {}), explicit: config.fetch("explicit", {}), ) end |
Instance Method Details
#binarydir ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
119 120 121 |
# File 'Library/Homebrew/cask/config.rb', line 119 def binarydir @binarydir ||= HOMEBREW_PREFIX/"bin" end |
#default ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
97 98 99 |
# File 'Library/Homebrew/cask/config.rb', line 97 def default @default ||= self.class.canonicalize(self.class.defaults) end |
#env ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'Library/Homebrew/cask/config.rb', line 101 def env @env ||= self.class.canonicalize( Homebrew::EnvConfig.cask_opts .select { |arg| arg.include?("=") } .map { |arg| arg.split("=", 2) } .map do |(flag, value)| key = flag.sub(/^--/, "") if key == "language" key = "languages" value = value.split(",") end [key, value] end, ) end |
#languages ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'Library/Homebrew/cask/config.rb', line 127 def languages [ *explicit[:languages], *env[:languages], *default[:languages], ].uniq.select do |lang| # Ensure all languages are valid. Locale.parse(lang) true rescue Locale::ParserError false end end |
#languages=(languages) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
141 142 143 |
# File 'Library/Homebrew/cask/config.rb', line 141 def languages=(languages) explicit[:languages] = languages end |
#manpagedir ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
123 124 125 |
# File 'Library/Homebrew/cask/config.rb', line 123 def manpagedir @manpagedir ||= HOMEBREW_PREFIX/"share/man" end |
#merge(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
155 156 157 |
# File 'Library/Homebrew/cask/config.rb', line 155 def merge(other) self.class.new(explicit: other.explicit.merge(explicit)) end |
#to_json(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
159 160 161 162 163 164 165 |
# File 'Library/Homebrew/cask/config.rb', line 159 def to_json(*args) { default: default, env: env, explicit: explicit, }.to_json(*args) end |