Module: Hbc::Scopes::ClassMethods

Defined in:
Library/Homebrew/cask/lib/hbc/scopes.rb

Instance Method Summary collapse

Instance Method Details

#allObject



8
9
10
# File 'Library/Homebrew/cask/lib/hbc/scopes.rb', line 8

def all
  all_tokens.map(&CaskLoader.public_method(:load))
end

#all_tapped_cask_dirsObject



12
13
14
# File 'Library/Homebrew/cask/lib/hbc/scopes.rb', line 12

def all_tapped_cask_dirs
  Tap.map(&:cask_dir).select(&:directory?)
end

#all_tokensObject



16
17
18
19
20
21
22
# File 'Library/Homebrew/cask/lib/hbc/scopes.rb', line 16

def all_tokens
  Tap.flat_map do |t|
    t.cask_files.map do |p|
      "#{t.name}/#{File.basename(p, ".rb")}"
    end
  end
end

#installedObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'Library/Homebrew/cask/lib/hbc/scopes.rb', line 24

def installed
  # CaskLoader.load has some DWIM which is slow.  Optimize here
  # by spoon-feeding CaskLoader.load fully-qualified paths.
  # TODO: speed up Hbc::Source::Tapped (main perf drag is calling Hbc.all_tokens repeatedly)
  # TODO: ability to specify expected source when calling CaskLoader.load (minor perf benefit)
  Pathname.glob(caskroom.join("*"))
          .sort
          .map do |caskroom_path|
            token = caskroom_path.basename.to_s

            path_to_cask = all_tapped_cask_dirs.find do |tap_dir|
              tap_dir.join("#{token}.rb").exist?
            end

            if path_to_cask
              CaskLoader.load(path_to_cask.join("#{token}.rb"))
            else
              CaskLoader.load(token)
            end
          end
end