Module: Cask::CaskLoader

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

Defined Under Namespace

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

Class Method Summary collapse

Class Method Details

.default_path(token) ⇒ Object



213
214
215
# File 'brew/Library/Homebrew/cask/cask_loader.rb', line 213

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

.for(ref) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'brew/Library/Homebrew/cask/cask_loader.rb', line 181

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) ⇒ Object



177
178
179
# File 'brew/Library/Homebrew/cask/cask_loader.rb', line 177

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

.path(ref) ⇒ Object



173
174
175
# File 'brew/Library/Homebrew/cask/cask_loader.rb', line 173

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

.tap_paths(token) ⇒ Object



217
218
219
220
# File 'brew/Library/Homebrew/cask/cask_loader.rb', line 217

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