Parent

Class/Module Index [+]

Quicksearch

Ruote::FlowDict

Wrapping a process expression and the current workitem as a Hash object ready for lookup at substitution time.

Public Class Methods

new(flow_expression, workitem, default_prefix='f') click to toggle source
# File lib/ruote/util/dollar.rb, line 71
def initialize (flow_expression, workitem, default_prefix='f')

  @fexp = flow_expression
  @workitem = workitem
  @default_prefix = default_prefix
end

Public Instance Methods

[](key) click to toggle source
# File lib/ruote/util/dollar.rb, line 78
def [] (key)

  return @fexp.fei.to_storage_id if key == 'fei'
  return @fexp.fei.wfid if key == 'wfid'
  return @fexp.fei.sub_wfid if key == 'sub_wfid'
  return @fexp.fei.expid if key == 'expid'

  pr, k = extract_prefix(key)

  # stage 0

  v = lookup(pr[0, 1], k)

  return v if v != nil

  # stage 1

  return '' if pr.size < 2

  lookup(pr[1, 1], k)
end
[]=(key, value) click to toggle source
# File lib/ruote/util/dollar.rb, line 100
def []= (key, value)

  pr, k = extract_prefix(key)
  pr = pr[0, 1]

  if pr == 'f'

    @workitem.set_attribute(k, value)

  elsif @fexp

    @fexp.set_variable(k, value)
  end
end
has_key?(key) click to toggle source
# File lib/ruote/util/dollar.rb, line 115
def has_key? (key)

  pr, k = extract_prefix(key)

  return true if pr == 'r'

  (self[key] != nil)
end

Protected Instance Methods

call_ruby(ruby_code) click to toggle source

The ${r:1+2} stuff. ("3").

# File lib/ruote/util/dollar.rb, line 152
def call_ruby (ruby_code)

  return '' if @fexp.context['ruby_eval_allowed'] != true

  engine_id = @fexp.context.engine_id

  wi = Ruote::Workitem.new(@workitem)
  workitem = wi

  fe = @fexp
  fexp = @fexp
  flow_expression = @fexp
  fei = @fexp.fei
    #
    # some simple notations made available to ${ruby:...}
    # notations

  @fexp.context.treechecker.check(ruby_code)

  # clear for eval...

  eval(ruby_code, binding()).to_s
end
d(s) click to toggle source

This 'd' function can be called from inside ${r:...} notations.

pdef = Ruote.process_definition do
  sequence do
    set 'f:toto' => 'person'
    echo "${r:d('f:toto')}"
  end
end

will yield "person".

# File lib/ruote/util/dollar.rb, line 187
def d (s)

  Rufus.dsub("${#{s}}", self)
end
extract_prefix(key) click to toggle source
# File lib/ruote/util/dollar.rb, line 136
def extract_prefix (key)

  i = key.index(':')

  return [ @default_prefix, key ] if not i

  pr = key[0..i-1] # until ':'
  pr = pr[0, 2] # the first two chars

  pr = pr[0, 1] unless (pr == 'vf') or (pr == 'fv')

  [ pr, key[i+1..-1] ]
end
lookup(pr, key) click to toggle source
# File lib/ruote/util/dollar.rb, line 126
def lookup (pr, key)

  case pr
    when 'v' then @fexp.lookup_variable(key)
    when 'f' then Ruote.lookup(@workitem['fields'], key)
    when 'r' then call_ruby(key)
    else nil
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.