Class: Dor::Workflow::Graph
- Inherits:
-
Object
- Object
- Dor::Workflow::Graph
- Defined in:
- lib/dor/workflow/graph.rb
Defined Under Namespace
Classes: Process
Constant Summary collapse
- FILL_COLORS =
{ 'waiting' => 'white', 'ready' => 'white', 'error' => '#8B0000', 'blocked' => 'white', 'completed' => 'darkgreen', 'unknown' => '#CFCFCF' }
- TEXT_COLORS =
{ 'waiting' => 'black', 'ready' => 'black', 'error' => 'white', 'blocked' => '#8B0000', 'completed' => 'white', 'unknown' => 'black' }
- PATTERNS =
{ 'waiting' => 'diagonals', 'ready' => 'filled', 'error' => 'filled', 'blocked' => 'diagonals', 'completed' => 'filled', 'unknown' => 'filled' }
- RESERVED_KEYS =
%w(repository name)
Instance Attribute Summary collapse
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#processes ⇒ Object
readonly
Returns the value of attribute processes.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
- .from_config(name, config, parent = nil) ⇒ Object
- .from_processes(repo, name, processes, parent = nil) ⇒ Object
Instance Method Summary collapse
- #add_process(name, external = false) ⇒ Object
- #finish ⇒ Object
-
#initialize(repo, name, parent = nil) ⇒ Graph
constructor
A new instance of Graph.
- #inspect ⇒ Object
- #method_missing(sym, *args) ⇒ Object
- #qname ⇒ Object
Constructor Details
#initialize(repo, name, parent = nil) ⇒ Graph
Returns a new instance of Graph.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dor/workflow/graph.rb', line 51 def initialize(repo, name, parent = nil) @repo = repo @name = name if parent.nil? @graph = GraphViz.new(qname) @root = add_nodes(name) else @graph = parent.subgraph(qname) @root = parent.add_nodes(name) end @graph[:truecolor => true] @root.shape = 'plaintext' @processes = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/dor/workflow/graph.rb', line 93 def method_missing(sym, *args) if @graph.respond_to?(sym) @graph.send(sym, *args) else super end end |
Instance Attribute Details
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
12 13 14 |
# File 'lib/dor/workflow/graph.rb', line 12 def graph @graph end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/dor/workflow/graph.rb', line 12 def name @name end |
#processes ⇒ Object (readonly)
Returns the value of attribute processes.
12 13 14 |
# File 'lib/dor/workflow/graph.rb', line 12 def processes @processes end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
12 13 14 |
# File 'lib/dor/workflow/graph.rb', line 12 def repo @repo end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
12 13 14 |
# File 'lib/dor/workflow/graph.rb', line 12 def root @root end |
Class Method Details
.from_config(name, config, parent = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dor/workflow/graph.rb', line 14 def self.from_config(name, config, parent = nil) wf = new(config['repository'], name, parent) config.keys.each { |p| wf.add_process(p.to_s) unless RESERVED_KEYS.include?(p) } config.keys.each { |p| next unless wf.processes[p] Array(config[p]['prerequisite']).each { |prereq| prereq.sub!(/^#{config['repository']}:#{name}:/e, '') if wf.processes[prereq] wf.processes[p].depends_on(wf.processes[prereq]) else wf.processes[p].depends_on(wf.add_process(prereq).set_status('external')) end } } wf.finish wf end |
.from_processes(repo, name, processes, parent = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dor/workflow/graph.rb', line 32 def self.from_processes(repo, name, processes, parent = nil) wf = new(repo, name, parent) processes.each { |p| wf.add_process(p.name).status = p.state || 'unknown' } processes.each { |p| p.prerequisite.each { |prereq| prereq.sub!(/^#{repo}:#{name}:/e, '') if wf.processes[prereq] wf.processes[p.name].depends_on(wf.processes[prereq]) else wf.processes[p.name].depends_on(wf.add_process(prereq).set_status('external')) end } } wf.finish wf end |
Instance Method Details
#add_process(name, external = false) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/dor/workflow/graph.rb', line 70 def add_process(name, external = false) pqname = name.split(/:/).length == 3 ? name : [qname, name].join(':') p = Process.new(self, pqname, name) @processes[name] = p p end |
#finish ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/dor/workflow/graph.rb', line 77 def finish @processes.values.each do |process| process.node.fontname = 'Helvetica' if process.id =~ %r{^#{qname}} && process.prerequisites.length == 0 (@root << process.node)[:arrowhead => 'none', :arrowtail => 'none', :dir => 'both', :style => 'invisible'] end end @root.fontname = 'Helvetica' self end |
#inspect ⇒ Object
89 90 91 |
# File 'lib/dor/workflow/graph.rb', line 89 def inspect "#{to_s[0..-2]} #{repo}:#{name} (#{processes.keys.join(', ')})>" end |
#qname ⇒ Object
66 67 68 |
# File 'lib/dor/workflow/graph.rb', line 66 def qname [@repo, @name].join(':') end |