Class: Cask::DSL Private

Inherits:
Object show all
Extended by:
Attrable
Includes:
OnSystem::MacOSOnly
Defined in:
cask/dsl.rb,
cask/dsl/base.rb,
cask/dsl/caveats.rb,
cask/dsl/version.rb,
cask/dsl/container.rb,
cask/dsl/preflight.rb,
cask/dsl/depends_on.rb,
cask/dsl/postflight.rb,
cask/dsl/conflicts_with.rb,
cask/dsl/uninstall_preflight.rb,
cask/dsl/uninstall_postflight.rb,
sorbet/rbi/parlour.rbi

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.

Class representing the domain-specific language used for casks.

Defined Under Namespace

Classes: Base, Caveats, ConflictsWith, Container, DependsOn, Postflight, Preflight, UninstallPostflight, UninstallPreflight, Version

Constant Summary collapse

ORDINARY_ARTIFACT_CLASSES =

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.

[
  Artifact::Installer,
  Artifact::App,
  Artifact::Artifact,
  Artifact::AudioUnitPlugin,
  Artifact::Binary,
  Artifact::Colorpicker,
  Artifact::Dictionary,
  Artifact::Font,
  Artifact::InputMethod,
  Artifact::InternetPlugin,
  Artifact::KeyboardLayout,
  Artifact::Manpage,
  Artifact::Pkg,
  Artifact::Prefpane,
  Artifact::Qlplugin,
  Artifact::Mdimporter,
  Artifact::ScreenSaver,
  Artifact::Service,
  Artifact::StageOnly,
  Artifact::Suite,
  Artifact::VstPlugin,
  Artifact::Vst3Plugin,
  Artifact::Uninstall,
  Artifact::Zap,
].freeze
ACTIVATABLE_ARTIFACT_CLASSES =

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.

(ORDINARY_ARTIFACT_CLASSES - [Artifact::StageOnly]).freeze
ARTIFACT_BLOCK_CLASSES =

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.

[
  Artifact::PreflightBlock,
  Artifact::PostflightBlock,
].freeze
DSL_METHODS =

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.

Set.new([
  :appcast,
  :arch,
  :artifacts,
  :auto_updates,
  :caveats,
  :conflicts_with,
  :container,
  :desc,
  :depends_on,
  :homepage,
  :language,
  :name,
  :sha256,
  :staged_path,
  :url,
  :version,
  :appdir,
  :deprecate!,
  :deprecated?,
  :deprecation_date,
  :deprecation_reason,
  :disable!,
  :disabled?,
  :disable_date,
  :disable_reason,
  :discontinued?, # TODO: remove once discontinued? is removed (4.5.0)
  :livecheck,
  :livecheckable?,
  :on_system_blocks_exist?,
  *ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key),
  *ACTIVATABLE_ARTIFACT_CLASSES.map(&:dsl_key),
  *ARTIFACT_BLOCK_CLASSES.flat_map { |klass| [klass.dsl_key, klass.uninstall_dsl_key] },
]).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Attrable

attr_predicate, attr_rw

Methods included from OnSystem::MacOSOnly

included, #on_arch_conditional

Constructor Details

#initialize(cask) ⇒ DSL

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 a new instance of DSL.



112
113
114
115
# File 'cask/dsl.rb', line 112

def initialize(cask)
  @cask = cask
  @token = cask.token
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ 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.



397
398
399
400
401
402
403
404
# File 'cask/dsl.rb', line 397

def method_missing(method, *)
  if method
    Utils.method_missing_message(method, token)
    nil
  else
    super
  end
end

Instance Attribute Details

#caskObject (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.



108
109
110
# File 'cask/dsl.rb', line 108

def cask
  @cask
end

#deprecation_dateObject (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.



108
109
110
# File 'cask/dsl.rb', line 108

def deprecation_date
  @deprecation_date
end

#deprecation_reasonObject (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.



108
109
110
# File 'cask/dsl.rb', line 108

def deprecation_reason
  @deprecation_reason
end

#disable_dateObject (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.



108
109
110
# File 'cask/dsl.rb', line 108

def disable_date
  @disable_date
end

#disable_reasonObject (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.



108
109
110
# File 'cask/dsl.rb', line 108

def disable_reason
  @disable_reason
end

#tokenObject (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.



108
109
110
# File 'cask/dsl.rb', line 108

def token
  @token
end

Instance Method Details

#appcast(*args, **kwargs) ⇒ Object



220
221
222
223
224
225
# File 'cask/dsl.rb', line 220

def appcast(*args, **kwargs)
  set_unique_stanza(:appcast, args.empty? && kwargs.empty?) do
    odisabled "the `appcast` stanza", "the `livecheck` stanza"
    true
  end
end

#appdirObject



411
412
413
414
415
# File 'cask/dsl.rb', line 411

def appdir
  return HOMEBREW_CASK_APPDIR_PLACEHOLDER if Cask.generating_hash?

  cask.config.appdir
end

#arch(arm: nil, intel: nil) ⇒ Object



265
266
267
268
269
270
271
272
273
# File 'cask/dsl.rb', line 265

def arch(arm: nil, intel: nil)
  should_return = arm.nil? && intel.nil?

  set_unique_stanza(:arch, should_return) do
    @on_system_blocks_exist = true

    on_arch_conditional(arm:, intel:)
  end
end

#artifactsObject

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.



295
296
297
# File 'cask/dsl.rb', line 295

def artifacts
  @artifacts ||= ArtifactSet.new
end

#auto_updates(auto_updates = nil) ⇒ Object



332
333
334
# File 'cask/dsl.rb', line 332

def auto_updates(auto_updates = nil)
  set_unique_stanza(:auto_updates, auto_updates.nil?) { auto_updates }
end

#caskroom_pathObject

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.



299
300
301
# File 'cask/dsl.rb', line 299

def caskroom_path
  cask.caskroom_path
end

#caveats(*strings, &block) ⇒ Object



312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'cask/dsl.rb', line 312

def caveats(*strings, &block)
  @caveats ||= DSL::Caveats.new(cask)
  if block
    @caveats.eval_caveats(&block)
  elsif strings.any?
    strings.each do |string|
      @caveats.eval_caveats { string }
    end
  else
    return @caveats.to_s
  end
  @caveats
end

#conflicts_with(**kwargs) ⇒ Object



290
291
292
293
# File 'cask/dsl.rb', line 290

def conflicts_with(**kwargs)
  # TODO: remove this constraint, and instead merge multiple conflicts_with stanzas
  set_unique_stanza(:conflicts_with, kwargs.empty?) { DSL::ConflictsWith.new(**kwargs) }
end

#container(**kwargs) ⇒ Object



228
229
230
231
232
# File 'cask/dsl.rb', line 228

def container(**kwargs)
  set_unique_stanza(:container, kwargs.empty?) do
    DSL::Container.new(**kwargs)
  end
end

#depends_on(**kwargs) ⇒ Object

depends_on uses a load method so that multiple stanzas can be merged.



277
278
279
280
281
282
283
284
285
286
287
# File 'cask/dsl.rb', line 277

def depends_on(**kwargs)
  @depends_on ||= DSL::DependsOn.new
  return @depends_on if kwargs.empty?

  begin
    @depends_on.load(**kwargs)
  rescue RuntimeError => e
    raise CaskInvalidError.new(cask, e)
  end
  @depends_on
end

#deprecate!(date:, because:) ⇒ Object



350
351
352
353
354
355
356
# File 'cask/dsl.rb', line 350

def deprecate!(date:, because:)
  @deprecation_date = Date.parse(date)
  return if @deprecation_date > Date.today

  @deprecation_reason = because
  @deprecated = true
end

#deprecated?Boolean

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:

  • (Boolean)


367
# File 'sorbet/rbi/parlour.rbi', line 367

def deprecated?; end

#desc(description = nil) ⇒ Object



126
127
128
# File 'cask/dsl.rb', line 126

def desc(description = nil)
  set_unique_stanza(:desc, description.nil?) { description }
end

#disable!(date:, because:) ⇒ Object



359
360
361
362
363
364
365
366
367
368
369
370
# File 'cask/dsl.rb', line 359

def disable!(date:, because:)
  @disable_date = Date.parse(date)

  if @disable_date > Date.today
    @deprecation_reason = because
    @deprecated = true
    return
  end

  @disable_reason = because
  @disabled = true
end

#disabled?Boolean

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:

  • (Boolean)


370
# File 'sorbet/rbi/parlour.rbi', line 370

def disabled?; end

#discontinued?Boolean

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:

  • (Boolean)


326
327
328
329
# File 'cask/dsl.rb', line 326

def discontinued?
  # odeprecated "`discontinued?`", "`deprecated?` or `disabled?`"
  @caveats&.discontinued? == true
end

#homepage(homepage = nil) ⇒ Object



152
153
154
# File 'cask/dsl.rb', line 152

def homepage(homepage = nil)
  set_unique_stanza(:homepage, homepage.nil?) { homepage }
end

#language(*args, default: false, &block) ⇒ 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.



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'cask/dsl.rb', line 156

def language(*args, default: false, &block)
  if args.empty?
    language_eval
  elsif block
    @language_blocks ||= {}
    @language_blocks[args] = block

    return unless default

    if !@cask.allow_reassignment && @language_blocks.default.present?
      raise CaskInvalidError.new(cask, "Only one default language may be defined.")
    end

    @language_blocks.default = block
  else
    raise CaskInvalidError.new(cask, "No block given to language stanza.")
  end
end

#language_evalObject

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.

Raises:



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'cask/dsl.rb', line 175

def language_eval
  return @language_eval if defined?(@language_eval)

  return @language_eval = nil if @language_blocks.blank?

  raise CaskInvalidError.new(cask, "No default language specified.") if @language_blocks.default.nil?

  locales = cask.config.languages
                .filter_map do |language|
                  Locale.parse(language)
                rescue Locale::ParserError
                  nil
                end

  locales.each do |locale|
    key = locale.detect(@language_blocks.keys)

    next if key.nil?

    return @language_eval = @language_blocks[key].call
  end

  @language_eval = @language_blocks.default.call
end

#languagesObject

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.



200
201
202
203
204
# File 'cask/dsl.rb', line 200

def languages
  return [] if @language_blocks.nil?

  @language_blocks.keys.flatten
end

#livecheck(&block) ⇒ Object



337
338
339
340
341
342
343
344
345
346
347
# File 'cask/dsl.rb', line 337

def livecheck(&block)
  @livecheck ||= Livecheck.new(cask)
  return @livecheck unless block

  if !@cask.allow_reassignment && @livecheckable
    raise CaskInvalidError.new(cask, "'livecheck' stanza may only appear once.")
  end

  @livecheckable = true
  @livecheck.instance_eval(&block)
end

#livecheckable?Boolean

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:

  • (Boolean)


373
# File 'sorbet/rbi/parlour.rbi', line 373

def livecheckable?; end

#name(*args) ⇒ Object



118
119
120
121
122
123
# File 'cask/dsl.rb', line 118

def name(*args)
  @name ||= []
  return @name if args.empty?

  @name.concat(args.flatten)
end

#on_system_blocks_exist?Boolean

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:

  • (Boolean)


364
# File 'sorbet/rbi/parlour.rbi', line 364

def on_system_blocks_exist?; end

#respond_to_missing?Boolean

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:

  • (Boolean)


406
407
408
# File 'cask/dsl.rb', line 406

def respond_to_missing?(*)
  true
end

#set_unique_stanza(stanza, should_return) ⇒ 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.



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'cask/dsl.rb', line 130

def set_unique_stanza(stanza, should_return)
  return instance_variable_get(:"@#{stanza}") if should_return

  unless @cask.allow_reassignment
    if instance_variable_defined?(:"@#{stanza}") && !@called_in_on_system_block
      raise CaskInvalidError.new(cask, "'#{stanza}' stanza may only appear once.")
    end

    if instance_variable_defined?(:"@#{stanza}_set_in_block") && @called_in_on_system_block
      raise CaskInvalidError.new(cask, "'#{stanza}' stanza may only be overridden once.")
    end
  end

  instance_variable_set(:"@#{stanza}_set_in_block", true) if @called_in_on_system_block
  instance_variable_set(:"@#{stanza}", yield)
rescue CaskInvalidError
  raise
rescue => e
  raise CaskInvalidError.new(cask, "'#{stanza}' stanza failed with: #{e}")
end

#sha256(arg = nil, arm: nil, intel: nil) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'cask/dsl.rb', line 246

def sha256(arg = nil, arm: nil, intel: nil)
  should_return = arg.nil? && arm.nil? && intel.nil?

  set_unique_stanza(:sha256, should_return) do
    @on_system_blocks_exist = true if arm.present? || intel.present?

    val = arg || on_arch_conditional(arm:, intel:)
    case val
    when :no_check
      val
    when String
      Checksum.new(val)
    else
      raise CaskInvalidError.new(cask, "invalid 'sha256' value: #{val.inspect}")
    end
  end
end

#staged_pathObject



304
305
306
307
308
309
# File 'cask/dsl.rb', line 304

def staged_path
  return @staged_path if @staged_path

  cask_version = version || :unknown
  @staged_path = caskroom_path.join(cask_version.to_s)
end

#url(*args, **options, &block) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
# File 'cask/dsl.rb', line 207

def url(*args, **options, &block)
  caller_location = T.must(caller_locations).fetch(0)

  set_unique_stanza(:url, args.empty? && options.empty? && !block) do
    if block
      URL.new(*args, **options, caller_location:, dsl: self, &block)
    else
      URL.new(*args, **options, caller_location:)
    end
  end
end

#version(arg = nil) ⇒ Object



235
236
237
238
239
240
241
242
243
# File 'cask/dsl.rb', line 235

def version(arg = nil)
  set_unique_stanza(:version, arg.nil?) do
    if !arg.is_a?(String) && arg != :latest
      raise CaskInvalidError.new(cask, "invalid 'version' value: #{arg.inspect}")
    end

    DSL::Version.new(arg)
  end
end