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.
99 100 101 |
# File 'lib/bricolage/jobnet.rb', line 99 def initialize @deps = Hash.new { Array.new } # {JobRef => [JobRef]} (dest->srcs) end |
Class Method Details
.build(jobnets) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/bricolage/jobnet.rb', line 90 def JobDAG.build(jobnets) graph = new jobnets.each do |net| graph.merge! net end graph.fix graph end |
Instance Method Details
#fix ⇒ Object
117 118 119 120 121 |
# File 'lib/bricolage/jobnet.rb', line 117 def fix @deps.freeze check_cycle check_orphan end |
#merge!(net) ⇒ Object
111 112 113 114 115 |
# File 'lib/bricolage/jobnet.rb', line 111 def merge!(net) net.each_dependencies do |ref, deps| @deps[ref] |= deps end end |
#sequential_jobs ⇒ Object
123 124 125 |
# File 'lib/bricolage/jobnet.rb', line 123 def sequential_jobs tsort.reject {|ref| ref.dummy? } end |
#to_hash ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/bricolage/jobnet.rb', line 103 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
133 134 135 |
# File 'lib/bricolage/jobnet.rb', line 133 def tsort_each_child(ref, &block) @deps.fetch(ref).each(&block) end |
#tsort_each_node(&block) ⇒ Object
129 130 131 |
# File 'lib/bricolage/jobnet.rb', line 129 def tsort_each_node(&block) @deps.each_key(&block) end |