Module: Cask::CaskLoader Private

Defined in:
cask/cask_loader.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Loads a cask from various sources.

Defined Under Namespace

Classes: FromContentLoader, FromInstanceLoader, FromPathLoader, FromTapLoader, FromTapPathLoader, FromURILoader, NullLoader

Class Method Summary collapse

Class Method Details

.default_path(token) ⇒ 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.



240
241
242
# File 'cask/cask_loader.rb', line 240

def self.default_path(token)
  Tap.default_cask_tap.cask_dir/"#{token.to_s.downcase}.rb"
end

.for(ref) ⇒ 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.



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'cask/cask_loader.rb', line 208

def self.for(ref)
  [
    FromInstanceLoader,
    FromContentLoader,
    FromURILoader,
    FromTapLoader,
    FromTapPathLoader,
    FromPathLoader,
  ].each do |loader_class|
    return loader_class.new(ref) if loader_class.can_load?(ref)
  end

  return FromTapPathLoader.new(default_path(ref)) if FromTapPathLoader.can_load?(default_path(ref))

  case (possible_tap_casks = tap_paths(ref)).count
  when 1
    return FromTapPathLoader.new(possible_tap_casks.first)
  when 2..Float::INFINITY
    loaders = possible_tap_casks.map(&FromTapPathLoader.method(:new))

    raise CaskError, <<~EOS
      Cask #{ref} exists in multiple taps:
      #{loaders.map { |loader| "  #{loader.tap}/#{loader.token}" }.join("\n")}
    EOS
  end

  possible_installed_cask = Cask.new(ref)
  return FromPathLoader.new(possible_installed_cask.installed_caskfile) if possible_installed_cask.installed?

  NullLoader.new(ref)
end

.load(ref, config: nil) ⇒ 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.



204
205
206
# File 'cask/cask_loader.rb', line 204

def self.load(ref, config: nil)
  self.for(ref).load(config: config)
end

.path(ref) ⇒ 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.



200
201
202
# File 'cask/cask_loader.rb', line 200

def self.path(ref)
  self.for(ref).path
end

.tap_paths(token) ⇒ 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.



244
245
246
247
# File 'cask/cask_loader.rb', line 244

def self.tap_paths(token)
  Tap.map { |t| t.cask_dir/"#{token.to_s.downcase}.rb" }
     .select(&:exist?)
end