Class: Cask::Config Private

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
cask/config.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.

Configuration for installing casks.

Constant Summary collapse

DEFAULT_DIRS =

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.

{
  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

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'cask/config.rb', line 102

def initialize(default: nil, env: nil, explicit: {}, ignore_invalid_keys: false)
  @default = self.class.canonicalize(self.class.defaults.merge(default)) if default
  @env = self.class.canonicalize(env) if env
  @explicit = self.class.canonicalize(explicit)

  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

#explicitHash{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.

Returns:



92
93
94
# File 'cask/config.rb', line 92

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.

Parameters:

Returns:



79
80
81
82
83
84
85
86
87
88
89
# File 'cask/config.rb', line 79

def self.canonicalize(config)
  config.map do |k, v|
    key = k.to_sym

    if DEFAULT_DIRS.key?(key)
      [key, Pathname(v).expand_path]
    else
      [key, v]
    end
  end.to_h
end

.defaultsObject

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.



36
37
38
39
40
# File 'cask/config.rb', line 36

def self.defaults
  {
    languages: LazyObject.new { MacOS.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.

Parameters:

Returns:

  • (T.attached_class)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'cask/config.rb', line 43

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, 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.

Parameters:

  • json (String)
  • ignore_invalid_keys (Boolean) (defaults to: false)

Returns:

  • (T.attached_class)


64
65
66
67
68
69
70
71
72
73
# File 'cask/config.rb', line 64

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: ignore_invalid_keys,
  )
end

Instance Method Details

#binarydirPathname

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.

Returns:



142
143
144
# File 'cask/config.rb', line 142

def binarydir
  @binarydir ||= HOMEBREW_PREFIX/"bin"
end

#defaultHash{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.

Returns:



118
119
120
# File 'cask/config.rb', line 118

def default
  @default ||= self.class.canonicalize(self.class.defaults)
end

#envHash{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.

Returns:



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'cask/config.rb', line 123

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

#explicit_sString

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.

Returns:



186
187
188
189
190
191
192
193
194
195
# File 'cask/config.rb', line 186

def explicit_s
  explicit.map do |key, value|
    # inverse of #env - converts :languages config key back to --language flag
    if key == :languages
      key = "language"
      value = T.cast(explicit.fetch(:languages, []), T::Array[String]).join(",")
    end
    "#{key}: \"#{value.to_s.sub(/^#{ENV['HOME']}/, "~")}\""
  end.join(", ")
end

#languagesArray<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.

Returns:



152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'cask/config.rb', line 152

def languages
  [
    *T.cast(explicit.fetch(:languages, []), T::Array[String]),
    *T.cast(env.fetch(:languages, []), T::Array[String]),
    *T.cast(default.fetch(:languages, []), T::Array[String]),
  ].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. 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.



166
167
168
# File 'cask/config.rb', line 166

def languages=(languages)
  explicit[:languages] = languages
end

#manpagedirPathname

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.

Returns:



147
148
149
# File 'cask/config.rb', line 147

def manpagedir
  @manpagedir ||= HOMEBREW_PREFIX/"share/man"
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.

Parameters:

Returns:

  • (T.self_type)


181
182
183
# File 'cask/config.rb', line 181

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.

Parameters:

  • options (T.untyped)

Returns:



198
199
200
201
202
203
204
# File 'cask/config.rb', line 198

def to_json(**options)
  {
    default:  default,
    env:      env,
    explicit: explicit,
  }.to_json(**options)
end