Class: Hashira::Analysis::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/hashira/analysis/graph.rb

Instance Method Summary collapse

Constructor Details

#initialize(project, trees, census) ⇒ Graph

Returns a new instance of Graph.



6
7
8
9
10
# File 'lib/hashira/analysis/graph.rb', line 6

def initialize(project, trees, census)
  @census = census
  @edge_map = EdgeMap.new(project, census)
  trees.each { |file, tree| @edge_map.record(file, tree) }
end

Instance Method Details

#cycle_path(package) ⇒ Object



45
# File 'lib/hashira/analysis/graph.rb', line 45

def cycle_path(package) = CycleSearch.new(dependencies, package).path

#cyclic?(package) ⇒ Boolean

Returns:

  • (Boolean)


41
# File 'lib/hashira/analysis/graph.rb', line 41

def cyclic?(package) = !!cycle_path(package)

#dependencies_of(package) ⇒ Object



14
# File 'lib/hashira/analysis/graph.rb', line 14

def dependencies_of(package) = dependencies[package].to_a.sort

#dependents_of(package) ⇒ Object



16
# File 'lib/hashira/analysis/graph.rb', line 16

def dependents_of(package) = packages.select { dependencies[_1].include?(package) }.sort

#edge_listObject



18
19
20
# File 'lib/hashira/analysis/graph.rb', line 18

def edge_list
  dependencies.sort.flat_map { |from, tos| tos.sort.map { Edge.new(from:, to: _1) } }
end

#evidence_for(from, to) ⇒ Object



29
# File 'lib/hashira/analysis/graph.rb', line 29

def evidence_for(from, to) = @edge_map.evidence[[from, to]]

#metric_for(package) ⇒ Object



31
32
33
34
35
# File 'lib/hashira/analysis/graph.rb', line 31

def metric_for(package)
  Metric.new(type_count: @census.type_count[package],
             afferent: dependents_of(package).size,
             efferent: dependencies[package].size)
end

#metricsObject



37
# File 'lib/hashira/analysis/graph.rb', line 37

def metrics = packages.to_h { [_1, metric_for(_1)] }

#packagesObject



12
# File 'lib/hashira/analysis/graph.rb', line 12

def packages = @census.packages

#sdp_violationsObject



39
# File 'lib/hashira/analysis/graph.rb', line 39

def sdp_violations = SdpCheck.new(dependencies, metrics).violations

#weakest_edge(path) ⇒ Object



47
48
49
# File 'lib/hashira/analysis/graph.rb', line 47

def weakest_edge(path)
  path.each_cons(2).min_by { |from, to| weight(from, to) }
end

#weight(from, to) ⇒ Object



43
# File 'lib/hashira/analysis/graph.rb', line 43

def weight(from, to) = evidence_for(from, to).size

#weighted_edgesObject



22
23
24
25
26
27
# File 'lib/hashira/analysis/graph.rb', line 22

def weighted_edges
  edge_list.map do |edge|
    from, to = edge.deconstruct
    [from, to, weight(from, to)]
  end
end