Class: Bricolage::JobNet

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

Overview

reopen as namespace

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.



174
175
176
177
178
179
# File 'lib/bricolage/jobnet.rb', line 174

def initialize(ref, location)
  @ref = ref
  @location = location
  @flow = {}   # Ref => [Ref] (src->dest)
  @deps = {}   # Ref => [Ref] (dest->src)
end

Instance Attribute Details

#refObject (readonly)

Returns the value of attribute ref.



185
186
187
# File 'lib/bricolage/jobnet.rb', line 185

def ref
  @ref
end

Class Method Details

.load(path, ref = JobNetRef.for_path(path)) ⇒ Object



160
161
162
163
164
165
166
# File 'lib/bricolage/jobnet.rb', line 160

def JobNet.load(path, ref = JobNetRef.for_path(path))
  File.open(path) {|f|
    Parser.new(ref).parse_stream(f)
  }
rescue SystemCallError => err
  raise ParameterError, "could not load jobnet: #{path} (#{err.message})"
end

.load_single_job(path, ref = JobNetRef.for_job_path(path)) ⇒ Object



168
169
170
171
172
# File 'lib/bricolage/jobnet.rb', line 168

def JobNet.load_single_job(path, ref = JobNetRef.for_job_path(path))
  jobnet_script = ref.name.to_s
  script_io = StringIO.new(jobnet_script)
  Parser.new(ref).parse_stream(script_io)
end

Instance Method Details

#add_edge(src, dest) ⇒ Object



199
200
201
202
# File 'lib/bricolage/jobnet.rb', line 199

def add_edge(src, dest)
  (@flow[src] ||= []).push dest
  (@deps[dest] ||= []).push src
end

#each_dependenciesObject



247
248
249
250
251
252
253
# File 'lib/bricolage/jobnet.rb', line 247

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

#endObject



191
192
193
# File 'lib/bricolage/jobnet.rb', line 191

def end
  @ref.end_ref
end

#fixObject

Adds dummy dependencies (@start and @end) to fix up all jobs into one DAG beginning with @start and ending with @end



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/bricolage/jobnet.rb', line 230

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

#inspectObject



181
182
183
# File 'lib/bricolage/jobnet.rb', line 181

def inspect
  "\#<#{self.class} #{ref}>"
end

#nameObject



195
196
197
# File 'lib/bricolage/jobnet.rb', line 195

def name
  @ref.to_s
end

#net_refsObject



224
225
226
# File 'lib/bricolage/jobnet.rb', line 224

def net_refs
  @deps.keys.select {|ref| ref.net? }
end

#refsObject



220
221
222
# File 'lib/bricolage/jobnet.rb', line 220

def refs
  @flow.keys | @flow.values.flatten
end

#startObject



187
188
189
# File 'lib/bricolage/jobnet.rb', line 187

def start
  @ref.start_ref
end

#to_deps_hashObject



212
213
214
215
216
217
218
# File 'lib/bricolage/jobnet.rb', line 212

def to_deps_hash
  h = {}
  @deps.each do |dest, srcs|
    h[dest.to_s] = srcs.map(&:to_s)
  end
  h
end

#to_hashObject



204
205
206
207
208
209
210
# File 'lib/bricolage/jobnet.rb', line 204

def to_hash
  h = {}
  @flow.each do |src, dests|
    h[src.to_s] = dests.map(&:to_s)
  end
  h
end