Class: Bricolage::JobDAG
- Inherits:
-
Object
- Object
- Bricolage::JobDAG
- Includes:
- TSort
- Defined in:
- lib/bricolage/jobnet.rb
Class Method Summary collapse
Instance Method Summary collapse
- #fix ⇒ Object
-
#initialize ⇒ JobDAG
constructor
A new instance of JobDAG.
- #merge!(net) ⇒ Object
- #sequential_jobs ⇒ Object
- #to_hash ⇒ Object
- #tsort_each_child(ref, &block) ⇒ Object
- #tsort_each_node(&block) ⇒ Object
Constructor Details
#initialize ⇒ JobDAG
Returns a new instance of JobDAG.
104 105 106 |
# File 'lib/bricolage/jobnet.rb', line 104 def initialize @deps = Hash.new { Array.new } # {JobRef => [JobRef]} (dest->srcs) end |
Class Method Details
.build(jobnets) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/bricolage/jobnet.rb', line 95 def JobDAG.build(jobnets) graph = new jobnets.each do |net| graph.merge! net end graph.fix graph end |
Instance Method Details
#fix ⇒ Object
122 123 124 125 126 |
# File 'lib/bricolage/jobnet.rb', line 122 def fix @deps.freeze check_cycle check_orphan end |
#merge!(net) ⇒ Object
116 117 118 119 120 |
# File 'lib/bricolage/jobnet.rb', line 116 def merge!(net) net.each_dependencies do |ref, deps| @deps[ref] |= deps end end |
#sequential_jobs ⇒ Object
128 129 130 |
# File 'lib/bricolage/jobnet.rb', line 128 def sequential_jobs tsort.reject {|ref| ref.dummy? } end |
#to_hash ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/bricolage/jobnet.rb', line 108 def to_hash h = {} @deps.each do |dest, srcs| h[dest.to_s] = srcs.map(&:to_s) end h end |
#tsort_each_child(ref, &block) ⇒ Object
138 139 140 |
# File 'lib/bricolage/jobnet.rb', line 138 def tsort_each_child(ref, &block) @deps.fetch(ref).each(&block) end |
#tsort_each_node(&block) ⇒ Object
134 135 136 |
# File 'lib/bricolage/jobnet.rb', line 134 def tsort_each_node(&block) @deps.each_key(&block) end |