Class: Bricolage::JobDAG

Inherits:
Object
  • Object
show all
Includes:
TSort
Defined in:
lib/bricolage/jobnet.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJobDAG

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

#fixObject



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_jobsObject



128
129
130
# File 'lib/bricolage/jobnet.rb', line 128

def sequential_jobs
  tsort.reject {|ref| ref.dummy? }
end

#to_hashObject



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