Class: Utils::TopologicalHash Private

Inherits:
Hash show all
Includes:
TSort
Defined in:
utils/topological_hash.rb

Overview

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

Topologically sortable hash map.

Class Method Summary collapse

Methods inherited from Hash

#assert_valid_keys, #blank?, #compact_blank, #deep_dup, #deep_merge, #deep_merge!, #deep_stringify_keys, #deep_stringify_keys!, #deep_symbolize_keys, #deep_symbolize_keys!, #deep_transform_keys, #deep_transform_keys!, #deep_transform_values, #deep_transform_values!, #present?

Class Method Details

.graph_package_dependencies(packages, accumulator = TopologicalHash.new) ⇒ TopologicalHash

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.

Parameters:

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'utils/topological_hash.rb', line 17

def self.graph_package_dependencies(packages, accumulator = TopologicalHash.new)
  packages = Array(packages)

  packages.each do |cask_or_formula|
    next if accumulator.key?(cask_or_formula)

    if cask_or_formula.is_a?(Cask::Cask)
      formula_deps = cask_or_formula.depends_on
                                    .formula
                                    .map { |f| Formula[f] }
      cask_deps = cask_or_formula.depends_on
                                 .cask
                                 .map { |c| Cask::CaskLoader.load(c, config: nil) }
    else
      formula_deps = cask_or_formula.deps
                                    .reject(&:build?)
                                    .reject(&:test?)
                                    .map(&:to_formula)
      cask_deps = cask_or_formula.requirements
                                 .filter_map(&:cask)
                                 .map { |c| Cask::CaskLoader.load(c, config: nil) }
    end

    accumulator[cask_or_formula] = formula_deps + cask_deps

    graph_package_dependencies(formula_deps, accumulator)
    graph_package_dependencies(cask_deps, accumulator)
  end

  accumulator
end