Parent

Class/Module Index [+]

Quicksearch

Ruote::ProcessStatus

A 'view' on the status of a process instance.

Returned by the process and the processes methods of the Engine.

Attributes

errors[R]

An array of errors currently plaguing the process instance. Hopefully, this array is empty.

expressions[R]

The expressions that compose the process instance.

Public Class Methods

new(context, expressions, errors) click to toggle source
# File lib/ruote/engine/process_status.rb, line 46
def initialize (context, expressions, errors)

  @expressions = expressions.collect { |e|
    Ruote::Exp::FlowExpression.from_h(context, e) }
  @expressions.sort! { |a, b| a.fei.expid <=> b.fei.expid }

  @errors = errors.collect { |e|
    ProcessError.new(e) }
  @errors.sort! { |a, b| a.fei.expid <=> b.fei.expid }
end

Public Instance Methods

all_tags() click to toggle source

Returns a hash tagname => array of feis of all the tags set in the process instance.

# File lib/ruote/engine/process_status.rb, line 125
def all_tags

  all_variables.inject({}) do |h, (fei, vars)|
    vars.each { |k, v| (h[k] ||= []) << v if FlowExpressionId.is_a_fei?(v) }
    h
  end
end
all_variables() click to toggle source

Returns a hash fei => variable_hash containing all the variable bindings (expression by expression) of the process instance.

# File lib/ruote/engine/process_status.rb, line 106
def all_variables

  @expressions.inject({}) do |h, exp|
    h[exp.fei] = exp.variables if exp.variables
    h
  end
end
current_tree() click to toggle source

Returns the current version of the process definition tree. If no manipulation (gardening) was performed on the tree, this method yields the same result as the original_tree method.

# File lib/ruote/engine/process_status.rb, line 228
def current_tree

  h = Ruote.decompose_tree(original_tree)

  @expressions.sort { |e0, e1|
    e0.fei.expid <=> e1.fei.expid
  }.each { |e|
    tree = if v = e.tree[1]['_triggered']
      t = original_tree_from_parent(e).dup
      t[1]['_triggered'] = v
      t
    else
      e.tree
    end
    h.merge!(Ruote.decompose_tree(tree, e.fei.expid))
  }

  Ruote.recompose_tree(h)
end
definition_name() click to toggle source
# File lib/ruote/engine/process_status.rb, line 144
def definition_name

  root_expression.attribute('name') || root_expression.attribute_text
end
definition_revision() click to toggle source
# File lib/ruote/engine/process_status.rb, line 149
def definition_revision

  root_expression.attribute('revision')
end
inspect() click to toggle source
# File lib/ruote/engine/process_status.rb, line 176
def inspect

  s = "== #{self.class} ==\n"
  s << "   expressions : #{@expressions.size}\n"
  @expressions.each do |e|
    s << "     #{e.fei.to_storage_id} : #{e}\n"
  end
  s << "   errors : #{@errors.size}\n"
  @errors.each do |e|
    s << "     #{e.fei.to_storage_id} :\n" if e.fei
    s << "     #{e.inspect}\n"
  end

  s
end
launched_time() click to toggle source

Returns a Time instance indicating when the process instance was launched.

# File lib/ruote/engine/process_status.rb, line 164
def launched_time

  root_expression.created_time
end
original_tree() click to toggle source

Returns the process definition tree as it was when this process instance was launched.

# File lib/ruote/engine/process_status.rb, line 157
def original_tree

  root_expression.original_tree
end
root_expression() click to toggle source

Returns the expression at the root of the process instance.

# File lib/ruote/engine/process_status.rb, line 59
def root_expression

  #@expressions.find { |e| e.fei.expid == '0' && e.fei.sub_wfid == nil }
    # vanilla implementation

  root_expressions.first
end
root_expression_for(fei) click to toggle source

Given an expression id, returns the root (top ancestor) for its expression.

# File lib/ruote/engine/process_status.rb, line 84
def root_expression_for (fei)

  sfei = Ruote.sid(fei)

  exp = @expressions.find { |fe| sfei == Ruote.sid(fe.fei) }

  return nil unless exp
  return exp if exp.parent_id.nil?

  root_expression_for(exp.parent_id)
end
root_expressions() click to toggle source

Returns a list of all the expressions that have no parent expression. The list is sorted with the deeper (closer to the original root) first.

# File lib/ruote/engine/process_status.rb, line 70
def root_expressions

  roots = @expressions.select { |e| e.h.parent_id == nil }

  roots = roots.inject({}) { |h, e|
    h["#{e.h.fei['expid']}__#{e.h.fei['sub_wfid']}"] = e; h
  }

  roots.keys.sort.collect { |k| roots[k] }
end
tags() click to toggle source

Returns a hash tagname => fei of tags set at the root of the process instance.

# File lib/ruote/engine/process_status.rb, line 117
def tags

  variables.select { |k, v| FlowExpressionId.is_a_fei?(v) }
end
to_dot(opts={}) click to toggle source
# File lib/ruote/engine/process_status.rb, line 192
def to_dot (opts={})

  s = [ "digraph \"process wfid #{wfid}\" {" ]
  @expressions.each { |e| s.push(*e.send(:to_dot, opts)) }
  @errors.each { |e| s.push(*e.send(:to_dot, opts)) }
  s << "}"

  s.join("\n")
end
to_h() click to toggle source
# File lib/ruote/engine/process_status.rb, line 202
def to_h

  h = {}

  ]
    wfid
    definition_name definition_revision
    original_tree current_tree
    variables tags
  ].each { |m| h[m] = self.send(m) }

  h['launched_time'] = launched_time.to_s

  # all_variables and all_tags ?

  h['root_expression'] = nil
  h['expressions'] = @expressions.collect { |e| e.fei.to_h }
  h['errors'] = @errors.collect { |e| e.to_h }

  h
end
to_s() click to toggle source
# File lib/ruote/engine/process_status.rb, line 169
def to_s

  "(process_status wfid '#{wfid}', " +
  "expressions #{@expressions.size}, " +
  "errors #{@errors.size})"
end
variables() click to toggle source

Returns the process variables set for this process instance.

# File lib/ruote/engine/process_status.rb, line 98
def variables

  root_expression.variables
end
wfid() click to toggle source

Returns the unique identifier for this process instance.

# File lib/ruote/engine/process_status.rb, line 135
def wfid

  begin
    root_expression.fei.wfid
  rescue
    @errors.first.fei.wfid
  end
end

Protected Instance Methods

original_tree_from_parent(e) click to toggle source
# File lib/ruote/engine/process_status.rb, line 250
def original_tree_from_parent (e)

  parent = @expressions.find { |exp| exp.fei == e.parent_id }

  parent ? parent.tree[2][e.fei.child_id] : e.tree
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.