Class: MilkTea::PackageGraph::Node

Inherits:
Data
  • Object
show all
Defined in:
lib/milk_tea/packages/graph.rb,
lib/milk_tea/packages/graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#edgesObject (readonly)

Returns the value of attribute edges

Returns:

  • (Object)

    the current value of edges



8
9
10
# File 'lib/milk_tea/packages/graph.rb', line 8

def edges
  @edges
end

#manifestObject (readonly)

Returns the value of attribute manifest

Returns:

  • (Object)

    the current value of manifest



8
9
10
# File 'lib/milk_tea/packages/graph.rb', line 8

def manifest
  @manifest
end

#sourceObject (readonly)

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



8
9
10
# File 'lib/milk_tea/packages/graph.rb', line 8

def source
  @source
end

Instance Method Details

#package_for_path(path, matches = []) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/milk_tea/packages/graph.rb', line 58

def package_for_path(path, matches = [])
  return nil unless path

  expanded_path = File.expand_path(path)
  matches << self if package_path?(expanded_path)
  edges.each do |edge|
    edge.node&.package_for_path(expanded_path, matches)
  end

  matches.max_by { |node| node.manifest.root_dir.length }
end

#packages(nodes = [], visited = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/milk_tea/packages/graph.rb', line 36

def packages(nodes = [], visited = {})
  return nodes if visited[manifest.manifest_path]

  visited[manifest.manifest_path] = true
  nodes << self
  edges.each do |edge|
    edge.node&.packages(nodes, visited)
  end
  nodes
end

#source_roots(roots = [], visited = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/milk_tea/packages/graph.rb', line 47

def source_roots(roots = [], visited = {})
  return roots if visited[manifest.manifest_path]

  visited[manifest.manifest_path] = true
  roots << manifest.source_root
  edges.each do |edge|
    edge.node&.source_roots(roots, visited)
  end
  roots
end

#tree_lines(indent = 0) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/milk_tea/packages/graph.rb', line 70

def tree_lines(indent = 0)
  lines = [("  " * indent) + manifest.package_name]
  edges.each do |edge|
    if edge.node
      lines.concat(edge.node.tree_lines(indent + 1))
    else
      lines << (("  " * (indent + 1)) + edge.dependency.name)
    end
  end
  lines
end