Class: Ruote::Exp::SetExpression

Inherits:
FlowExpression show all
Defined in:
lib/ruote/exp/fe_set.rb

Overview

Setting a workitem field or a process variable.

sequence do
  set :field => 'subject', :value => 'food and beverage'
  set :field => 'date', :val => 'tomorrow'
  participant :ref => 'attendees'
end

:field can be abbreviated to :f or :fld. :variable can be abbreviated to :v or :var. Likewise, :val and :value are interchangeable.

field_value, variable_value

Usually, grabbing a value from a field or a value will look like

set :f => 'my_field', :value => '${v:my_variable}'

But doing those ${} substitutions always result in a string result. What if the variable or the field holds a non-string value ?

set :f => 'my_field', :var_value => 'my_variable'

Is the way to go then. ‘set’ understands v_value, var_value, variable_value and f_value, fld_value and field_value.

:escape

If the value to insert contains ${} stuff but this has to be preserved, setting the attribute :escape to true will do the trick.

set :f => 'my_field', :value => 'oh and ${whatever}', :escape => true

ruote 2.0’s shorter form

Ruote 2.0 introduces a shorter form for the ‘set’ expression :

sequence do
  set :field => 'f', :value => 'val0'
  set :variable => 'v', :value => 'val1'
  set :field => 'f_${v:v}', :value => 'val2'
end

can be rewritten as

sequence do
  set 'f:f' => 'val0'
  set 'v:v' => 'val1'
  set 'f:f_${v:v}' => 'val2'
end

since ‘f:’ is the default for the ‘dollar notation’, the shortest form becomes

sequence do
  set 'f' => 'val0'
  set 'v:v' => 'val1'
  set 'f_${v:v}' => 'val2'
end

set and rset

Some gems (Sinatra) for example may provide a set method that hides calls to set when building process definitions (see groups.google.com/group/openwferu-users/browse_thread/thread/9ac606e30ada686e)

A workaround is to write ‘rset’ instead of ‘set’.

rset 'customer' => 'Jeff'

unset

‘unset’ is the counterpart to ‘set’, it removes a field (or a variable)

unset :field => 'customer_name'
unset :f => 'customer_name'
unset :variable => 'vx'
unset :var => 'vx'
unset :v => 'vx'

or simply

unset 'f:customer_name'
unset 'customer_name' # yes, it's field by default
unset 'v:vx'

Direct Known Subclasses

IncExpression

Constant Summary

Constants inherited from FlowExpression

FlowExpression::COMMON_ATT_KEYS

Instance Attribute Summary

Attributes inherited from FlowExpression

#context, #error, #h

Instance Method Summary collapse

Methods inherited from FlowExpression

#ancestor?, #att, #attribute, #attribute_text, #attributes, #cancel, #compile_atts, #compile_variables, do_action, #do_apply, #do_cancel, #do_fail, #do_pause, #do_persist, #do_reply, #do_resume, #do_unpersist, #expand_atts, #fei, fetch, from_h, #handle_on_error, #has_attribute, #initial_persist, #initialize, #iterative_var_lookup, #launch_sub, #lookup_on_error, #lookup_val, #lookup_val_prefix, #lookup_variable, #name, names, #parent, #parent_id, #persist_or_raise, #reply_to_parent, #set_variable, #to_h, #tree, #tree_children, #try_persist, #try_unpersist, #unpersist_or_raise, #unset_variable, #update_tree, #variables

Methods included from WithMeta

#class_def, included

Methods included from WithH

included

Constructor Details

This class inherits a constructor from Ruote::Exp::FlowExpression

Instance Method Details

#applyObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/ruote/exp/fe_set.rb', line 118

def apply

  opts = { :escape => attribute(:escape) }

  value = lookup_val(opts)
    # a nil value is totally OK

  if var_key = has_attribute(:v, :var, :variable)

    set_v(attribute(var_key), value, name == 'unset')

  elsif field_key = has_attribute(:f, :fld, :field)

    set_f(attribute(field_key), value, name == 'unset')

  elsif value == nil && kv = expand_atts(opts).find { |k, v| k != 'escape' }

    kv << (name == 'unset')

    set_vf(*kv)

  else

    raise ArgumentError.new(
      "missing a variable or field target in #{tree.inspect}")
  end

  reply_to_parent(h.applied_workitem)
end

#reply(workitem) ⇒ Object



148
149
150
151
# File 'lib/ruote/exp/fe_set.rb', line 148

def reply(workitem)

  # never called
end