| Class | OpenWFE::RevalExpression |
| In: |
lib/openwfe/expressions/fe_misc.rb
|
| Parent: | FlowExpression |
Evals some Ruby code contained within the process definition or within the workitem.
The code is evaluated at a SAFE level of 3.
If the :ruby_eval_allowed isn‘t set to true (engine.application_context[:ruby_eval_allowed] = true), this expression will throw an exception at apply.
some examples :
<reval>
workitem.customer_name = "doug"
# or for short
wi.customer_address = "midtown 21_21 design"
</reval>
in a Ruby process definition :
sequence do
_set :field => "customer" do
reval """
{
:name => "Cheezburger",
:age => 34,
:comment => "I can haz ?",
:timestamp => Time.now.to_s
}
"""
end
end
Don‘t embed too much Ruby into your process definitions, it might hurt…
Reval can also be used with the ‘code’ attribute (or ‘field-code’ or ‘variable-code’) :
<reval field-code="f0" />
to eval the Ruby code held in the field named "f0".
| SAFETY_LEVEL | = | 3 |
See for an explanation on Ruby safety levels : www.rubycentral.com/book/taint.html
‘reval’ is entitled a safe level of 3. |
# File lib/openwfe/expressions/fe_misc.rb, line 147
147: def reply (workitem)
148:
149: raise "evaluation of ruby code is not allowed" \
150: if @application_context[:ruby_eval_allowed] != true
151:
152: code = lookup_vf_attribute(workitem, 'code') || workitem.get_result
153: code = code.to_s
154:
155: wi = workitem
156: # so that the ruby code being evaluated sees 'wi' and 'workitem'
157:
158: result = Rufus::eval_safely code, SAFETY_LEVEL, binding()
159:
160: workitem.set_result(result) \
161: if result != nil # 'false' is a valid result
162:
163: reply_to_parent workitem
164: end