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.
108 109 110 |
# File 'lib/bricolage/jobnet.rb', line 108 def initialize @deps = Hash.new { Array.new } # {JobRef => [JobRef]} (dest->srcs) end |
Class Method Details
.build(jobnets) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/bricolage/jobnet.rb', line 99 def JobDAG.build(jobnets) graph = new jobnets.each do |net| graph.merge! net end graph.fix graph end |
Instance Method Details
#fix ⇒ Object
126 127 128 129 130 |
# File 'lib/bricolage/jobnet.rb', line 126 def fix @deps.freeze check_cycle check_orphan end |
#merge!(net) ⇒ Object
120 121 122 123 124 |
# File 'lib/bricolage/jobnet.rb', line 120 def merge!(net) net.each_dependencies do |ref, deps| @deps[ref] |= deps end end |
#sequential_jobs ⇒ Object
132 133 134 |
# File 'lib/bricolage/jobnet.rb', line 132 def sequential_jobs tsort.reject {|ref| ref.dummy? } end |
#to_hash ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/bricolage/jobnet.rb', line 112 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
142 143 144 |
# File 'lib/bricolage/jobnet.rb', line 142 def tsort_each_child(ref, &block) @deps.fetch(ref).each(&block) end |
#tsort_each_node(&block) ⇒ Object
138 139 140 |
# File 'lib/bricolage/jobnet.rb', line 138 def tsort_each_node(&block) @deps.each_key(&block) end |