Class: Utils::TopologicalHash

Inherits:
Hash
  • Object
show all
Extended by:
T::Sig
Includes:
TSort
Defined in:
utils/topological_hash.rb

Overview

Topologically sortable hash map.

Class Method Summary collapse

Class Method Details

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

Parameters:

Returns:



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
48
49
50
51
# File 'utils/topological_hash.rb', line 19

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

  packages.each do |cask_or_formula|
    next accumulator 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?)
                                    .map(&:to_formula)
      cask_deps = cask_or_formula.requirements
                                 .map(&:cask)
                                 .compact
                                 .map { |c| Cask::CaskLoader.load(c, config: nil) }
    end

    accumulator[cask_or_formula] ||= []
    accumulator[cask_or_formula] += formula_deps
    accumulator[cask_or_formula] += cask_deps

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

  accumulator
end