Module: Hbc::CaskLoader

Defined in:
Library/Homebrew/cask/lib/hbc/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



207
208
209
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 207

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

.for(ref) ⇒ Object



171
172
173
174
175
176
177
178
179
180
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
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 171

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

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

  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)
  if possible_installed_cask.installed?
    return FromPathLoader.new(possible_installed_cask.installed_caskfile)
  end

  NullLoader.new(ref)
end

.load(ref) ⇒ Object



167
168
169
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 167

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

.path(ref) ⇒ Object



163
164
165
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 163

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

.tap_paths(token) ⇒ Object



211
212
213
214
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 211

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