Module: Cask::CaskLoader Private

Defined in:
Library/Homebrew/cask/cask_loader.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

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. You should avoid using this method if possible, as it may be removed or be changed in the future.


234
235
236
# File 'Library/Homebrew/cask/cask_loader.rb', line 234

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. You should avoid using this method if possible, as it may be removed or be changed in the future.


202
203
204
205
206
207
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
# File 'Library/Homebrew/cask/cask_loader.rb', line 202

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. You should avoid using this method if possible, as it may be removed or be changed in the future.


198
199
200
# File 'Library/Homebrew/cask/cask_loader.rb', line 198

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

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


194
195
196
# File 'Library/Homebrew/cask/cask_loader.rb', line 194

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

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


238
239
240
241
# File 'Library/Homebrew/cask/cask_loader.rb', line 238

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