Class: Hashira::Coupling::Graph
- Inherits:
-
Object
- Object
- Hashira::Coupling::Graph
- Defined in:
- lib/hashira/coupling/graph.rb
Instance Attribute Summary collapse
-
#cycles ⇒ Object
readonly
Returns the value of attribute cycles.
-
#trees ⇒ Object
readonly
Returns the value of attribute trees.
Instance Method Summary collapse
- #charge(file) ⇒ Object
- #constants(edge) ⇒ Object
- #edges ⇒ Object
- #evidence(from, to) ⇒ Object
- #folds ⇒ Object
- #incoming(package) ⇒ Object
-
#initialize(project, trees, census) ⇒ Graph
constructor
A new instance of Graph.
- #metric(package) ⇒ Object
- #metrics ⇒ Object
- #outgoing(package) ⇒ Object
- #packages ⇒ Object
- #packaging ⇒ Object
- #usage(package) ⇒ Object
- #violations ⇒ Object
- #weight(from, to) ⇒ Object
- #weighted ⇒ Object
Constructor Details
#initialize(project, trees, census) ⇒ Graph
Returns a new instance of Graph.
4 5 6 7 8 9 10 |
# File 'lib/hashira/coupling/graph.rb', line 4 def initialize(project, trees, census) @census = census @trees = trees @map = Hashira::Coupling::EdgeMap.new(census) trees.each { |file, tree| @map.record(project.relative(file), file, tree) } @cycles = Hashira::Coupling::Cycles.new(@map.dependencies, self) end |
Instance Attribute Details
#cycles ⇒ Object (readonly)
Returns the value of attribute cycles.
12 13 14 |
# File 'lib/hashira/coupling/graph.rb', line 12 def cycles @cycles end |
#trees ⇒ Object (readonly)
Returns the value of attribute trees.
12 13 14 |
# File 'lib/hashira/coupling/graph.rb', line 12 def trees @trees end |
Instance Method Details
#charge(file) ⇒ Object
14 |
# File 'lib/hashira/coupling/graph.rb', line 14 def charge(file) = @census.charge(file, []) |
#constants(edge) ⇒ Object
41 42 43 44 |
# File 'lib/hashira/coupling/graph.rb', line 41 def constants(edge) from, to = edge.deconstruct @map.usage[[from, to]].sort end |
#edges ⇒ Object
26 27 28 |
# File 'lib/hashira/coupling/graph.rb', line 26 def edges dependencies.sort.flat_map { |from, tos| tos.sort.map { Hashira::Coupling::Edge.new(from:, to: it) } } end |
#evidence(from, to) ⇒ Object
37 |
# File 'lib/hashira/coupling/graph.rb', line 37 def evidence(from, to) = @map.evidence[[from, to]] |
#folds ⇒ Object
20 |
# File 'lib/hashira/coupling/graph.rb', line 20 def folds = @census.folds |
#incoming(package) ⇒ Object
24 |
# File 'lib/hashira/coupling/graph.rb', line 24 def incoming(package) = packages.select { dependencies[it].include?(package) }.sort |
#metric(package) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/hashira/coupling/graph.rb', line 46 def metric(package) Hashira::Coupling::Metric.new( types: @census.types[package], afferent: incoming(package).size, efferent: dependencies[package].size ) end |
#metrics ⇒ Object
54 |
# File 'lib/hashira/coupling/graph.rb', line 54 def metrics = packages.to_h { [it, metric(it)] } |
#outgoing(package) ⇒ Object
22 |
# File 'lib/hashira/coupling/graph.rb', line 22 def outgoing(package) = dependencies[package].to_a.sort |
#packages ⇒ Object
16 |
# File 'lib/hashira/coupling/graph.rb', line 16 def packages = (@census.packages | @map.dependencies.keys) |
#packaging ⇒ Object
18 |
# File 'lib/hashira/coupling/graph.rb', line 18 def packaging = @census.packaging |
#usage(package) ⇒ Object
39 |
# File 'lib/hashira/coupling/graph.rb', line 39 def usage(package) = incoming(package).to_h { [it, @map.usage[[it, package]]] } |
#violations ⇒ Object
56 |
# File 'lib/hashira/coupling/graph.rb', line 56 def violations = Hashira::Coupling::SdpCheck.new(dependencies, metrics).violations |
#weight(from, to) ⇒ Object
58 |
# File 'lib/hashira/coupling/graph.rb', line 58 def weight(from, to) = evidence(from, to).size |
#weighted ⇒ Object
30 31 32 33 34 35 |
# File 'lib/hashira/coupling/graph.rb', line 30 def weighted edges.map do |edge| from, to = edge.deconstruct [from, to, weight(from, to)] end end |