Class: Bricolage::RootJobNet

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

Overview

Represents “first” jobnet given by command line (e.g. bricolage-jobnet some.jobnet)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jobnet_loader, start_jobnet, path = nil) ⇒ RootJobNet

Returns a new instance of RootJobNet.



35
36
37
38
39
40
41
# File 'lib/bricolage/jobnet.rb', line 35

def initialize(jobnet_loader, start_jobnet, path = nil)
  @jobnet_loader = jobnet_loader
  @start_jobnet = start_jobnet
  @path = path
  @jobnets = {start_jobnet.ref => start_jobnet}
  @graph = nil
end

Instance Attribute Details

#start_jobnetObject (readonly)

Returns the value of attribute start_jobnet.



52
53
54
# File 'lib/bricolage/jobnet.rb', line 52

def start_jobnet
  @start_jobnet
end

Class Method Details

.load(ctx, path) ⇒ Object



17
18
19
20
21
22
# File 'lib/bricolage/jobnet.rb', line 17

def RootJobNet.load(ctx, path)
  root = new(JobNet::FileLoader.new(ctx), JobNet.load(path), path)
  root.load_recursive
  root.fix
  root
end

.load_auto(ctx, pathes) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/bricolage/jobnet.rb', line 8

def RootJobNet.load_auto(ctx, pathes)
  pathes = Array(pathes)
  if pathes.size == 1 and pathes.first.extname == '.jobnet'
    load(ctx, pathes.first)
  else
    load_multiple_jobs(ctx, pathes)
  end
end

.load_multiple_jobs(ctx, pathes) ⇒ Object



28
29
30
31
32
33
# File 'lib/bricolage/jobnet.rb', line 28

def RootJobNet.load_multiple_jobs(ctx, pathes)
  root = new(JobNet::FileLoader.new(ctx), JobNet.load_multiple_jobs(pathes), pathes.first)
  root.load_recursive
  root.fix
  root
end

.load_single_job(ctx, path) ⇒ Object



24
25
26
# File 'lib/bricolage/jobnet.rb', line 24

def RootJobNet.load_single_job(ctx, path)
  load_multiple_jobs(ctx, [path])
end

Instance Method Details

#each_jobnet(&block) ⇒ Object



54
55
56
# File 'lib/bricolage/jobnet.rb', line 54

def each_jobnet(&block)
  @jobnets.each_value(&block)
end

#fixObject



81
82
83
84
85
86
87
# File 'lib/bricolage/jobnet.rb', line 81

def fix
  each_jobnet do |net|
    net.fix
  end
  @jobnets.freeze
  @dag = JobDAG.build(jobnets)
end

#idObject



43
44
45
46
47
48
49
50
# File 'lib/bricolage/jobnet.rb', line 43

def id
  return nil unless @path
  @id ||= begin
    subsys = @path.dirname.basename
    base = @path.basename.to_s.sub(/\..*\z/, '')
    "#{subsys}/#{base}"
  end
end

#jobnetsObject



58
59
60
# File 'lib/bricolage/jobnet.rb', line 58

def jobnets
  @jobnets.values
end

#load_recursiveObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/bricolage/jobnet.rb', line 62

def load_recursive
  unresolved = [@start_jobnet]
  until unresolved.empty?
    loaded = []
    unresolved.each do |net|
      net.net_refs.each do |ref|
        next if ref.jobnet
        unless net = @jobnets[ref]
          net = @jobnet_loader.load(ref)
          @jobnets[ref] = net
          loaded.push net
        end
        ref.jobnet = net
      end
    end
    unresolved = loaded
  end
end

#sequential_jobsObject



89
90
91
# File 'lib/bricolage/jobnet.rb', line 89

def sequential_jobs
  @dag.sequential_jobs
end