Class: Cask::DSL Private

Inherits:
Object
  • Object
show all
Defined in:
cask/dsl.rb,
cask/dsl/base.rb,
cask/dsl/appcast.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

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: Appcast, 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::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,
  :artifacts,
  :auto_updates,
  :caveats,
  :conflicts_with,
  :container,
  :desc,
  :depends_on,
  :homepage,
  :language,
  :languages,
  :name,
  :sha256,
  :staged_path,
  :url,
  :version,
  :appdir,
  :discontinued?,
  :livecheck,
  :livecheckable?,
  *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

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.



94
95
96
97
# File 'cask/dsl.rb', line 94

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.



330
331
332
333
334
335
336
337
# File 'cask/dsl.rb', line 330

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.



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

def cask
  @cask
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.



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

def token
  @token
end

Instance Method Details

#appcast(*args) ⇒ Object



196
197
198
# File 'cask/dsl.rb', line 196

def appcast(*args)
  set_unique_stanza(:appcast, args.empty?) { DSL::Appcast.new(*args) }
end

#appdirObject



344
345
346
# File 'cask/dsl.rb', line 344

def appdir
  cask.config.appdir
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.



252
253
254
# File 'cask/dsl.rb', line 252

def artifacts
  @artifacts ||= SortedSet.new
end

#auto_updates(auto_updates = nil) ⇒ Object



288
289
290
# File 'cask/dsl.rb', line 288

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.



256
257
258
# File 'cask/dsl.rb', line 256

def caskroom_path
  cask.caskroom_path
end

#caveats(*strings, &block) ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'cask/dsl.rb', line 269

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(*args) ⇒ Object



247
248
249
250
# File 'cask/dsl.rb', line 247

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

#container(*args) ⇒ Object



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

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

#depends_on(*args) ⇒ Object

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



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

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

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

#desc(description = nil) ⇒ Object



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

def desc(description = nil)
  set_unique_stanza(:desc, description.nil?) { description }
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)


283
284
285
# File 'cask/dsl.rb', line 283

def discontinued?
  @caveats&.discontinued?
end

#homepage(homepage = nil) ⇒ Object



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

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.



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

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

    return unless default

    unless @language_blocks.default.nil?
      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:



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

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
                .map do |language|
                  Locale.parse(language)
                rescue Locale::ParserError
                  nil
                end
                .compact

  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.



176
177
178
179
180
# File 'cask/dsl.rb', line 176

def languages
  return [] if @language_blocks.nil?

  @language_blocks.keys.flatten
end

#livecheck(&block) ⇒ Object

Raises:



293
294
295
296
297
298
299
300
301
# File 'cask/dsl.rb', line 293

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

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

  @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)


303
304
305
# File 'cask/dsl.rb', line 303

def livecheckable?
  @livecheckable == true
end

#name(*args) ⇒ Object



100
101
102
103
104
105
# File 'cask/dsl.rb', line 100

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

  @name.concat(args.flatten)
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)


339
340
341
# File 'cask/dsl.rb', line 339

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.



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'cask/dsl.rb', line 112

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

  if instance_variable_defined?("@#{stanza}")
    raise CaskInvalidError.new(cask, "'#{stanza}' stanza may only appear once.")
  end

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

#sha256(arg = nil) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
# File 'cask/dsl.rb', line 219

def sha256(arg = nil)
  set_unique_stanza(:sha256, arg.nil?) do
    case arg
    when :no_check
      arg
    when String
      Checksum.new(arg)
    else
      raise CaskInvalidError.new(cask, "invalid 'sha256' value: #{arg.inspect}")
    end
  end
end

#staged_pathObject



261
262
263
264
265
266
# File 'cask/dsl.rb', line 261

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



183
184
185
186
187
188
189
190
191
192
193
# File 'cask/dsl.rb', line 183

def url(*args, **options, &block)
  caller_location = caller_locations[0]

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

#version(arg = nil) ⇒ Object



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

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