Class: Bricolage::JobNet
- Inherits:
-
Object
show all
- Defined in:
- lib/bricolage/jobnet.rb,
lib/bricolage/jobnet.rb
Overview
Defined Under Namespace
Classes: FileLoader, JobNetRef, JobRef, Location, Parser, Ref
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(ref, location) ⇒ JobNet
Returns a new instance of JobNet.
198
199
200
201
202
203
|
# File 'lib/bricolage/jobnet.rb', line 198
def initialize(ref, location)
@ref = ref
@location = location
@flow = {} @deps = {} end
|
Instance Attribute Details
#ref ⇒ Object
Returns the value of attribute ref.
209
210
211
|
# File 'lib/bricolage/jobnet.rb', line 209
def ref
@ref
end
|
Class Method Details
.load(path, ref = JobNetRef.for_path(path)) ⇒ Object
.load_multiple_jobs(pathes, ref = JobNetRef.for_job_path(pathes.first)) ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/bricolage/jobnet.rb', line 177
def JobNet.load_multiple_jobs(pathes, ref = JobNetRef.for_job_path(pathes.first))
jobnet_script = StringIO.new
prev = nil
pathes.each do |path|
jobnet_script.print '-> ' if prev
case path.extname
when '.job'
r = JobRef.for_path(path)
jobnet_script.puts r.to_s
when '.jobnet'
r = JobNetRef.for_job_path(path)
jobnet_script.puts r.to_s
else
raise ParameterError, "is not a job nor a jobnet: #{path}"
end
prev = r
end
jobnet_script.rewind
Parser.new(ref).parse_stream(jobnet_script)
end
|
.load_single_job(path, ref = JobNetRef.for_job_path(path)) ⇒ Object
173
174
175
|
# File 'lib/bricolage/jobnet.rb', line 173
def JobNet.load_single_job(path, ref = JobNetRef.for_job_path(path))
load_multiple_jobs([path], ref)
end
|
Instance Method Details
#add_edge(src, dest) ⇒ Object
223
224
225
226
|
# File 'lib/bricolage/jobnet.rb', line 223
def add_edge(src, dest)
(@flow[src] ||= []).push dest
(@deps[dest] ||= []).push src
end
|
#each_dependencies ⇒ Object
271
272
273
274
275
276
277
|
# File 'lib/bricolage/jobnet.rb', line 271
def each_dependencies
@deps.each do |ref, deps|
dest = (ref.net? ? ref.start : ref)
srcs = deps.map {|r| r.net? ? r.end : r }
yield dest, srcs
end
end
|
#end ⇒ Object
215
216
217
|
# File 'lib/bricolage/jobnet.rb', line 215
def end
@ref.end_ref
end
|
#fix ⇒ Object
Adds dummy dependencies (@start and @end) to fix up all jobs into one DAG beginning with @start and ending with @end
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
# File 'lib/bricolage/jobnet.rb', line 254
def fix
refs.each do |ref|
next if ref.dummy?
unless @deps[ref]
(@flow[self.start] ||= []).push ref
@deps[ref] = [self.start]
end
unless @flow[ref]
(@flow[ref] ||= []).push self.end
(@deps[self.end] ||= []).push ref
end
end
@deps[self.start] ||= []
@flow.freeze
@deps.freeze
end
|
#inspect ⇒ Object
205
206
207
|
# File 'lib/bricolage/jobnet.rb', line 205
def inspect
"\#<#{self.class} #{ref}>"
end
|
#name ⇒ Object
219
220
221
|
# File 'lib/bricolage/jobnet.rb', line 219
def name
@ref.to_s
end
|
#net_refs ⇒ Object
248
249
250
|
# File 'lib/bricolage/jobnet.rb', line 248
def net_refs
@deps.keys.select {|ref| ref.net? }
end
|
#refs ⇒ Object
244
245
246
|
# File 'lib/bricolage/jobnet.rb', line 244
def refs
@flow.keys | @flow.values.flatten
end
|
#start ⇒ Object
211
212
213
|
# File 'lib/bricolage/jobnet.rb', line 211
def start
@ref.start_ref
end
|
#to_deps_hash ⇒ Object
236
237
238
239
240
241
242
|
# File 'lib/bricolage/jobnet.rb', line 236
def to_deps_hash
h = {}
@deps.each do |dest, srcs|
h[dest.to_s] = srcs.map(&:to_s)
end
h
end
|
#to_hash ⇒ Object
228
229
230
231
232
233
234
|
# File 'lib/bricolage/jobnet.rb', line 228
def to_hash
h = {}
@flow.each do |src, dests|
h[src.to_s] = dests.map(&:to_s)
end
h
end
|