Class: OpenWFE::RevalExpression
- Inherits:
-
FlowExpression
- Object
- ObjectWithMeta
- FlowExpression
- OpenWFE::RevalExpression
- Includes:
- ValueMixin
- Defined in:
- lib/openwfe/expressions/fe_misc.rb
Overview
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”.
Constant Summary collapse
- SAFETY_LEVEL =
See for an explanation on Ruby safety levels : www.rubycentral.com/book/taint.html
‘reval’ is entitled a safe level of 3.
3
Instance Attribute Summary
Attributes inherited from FlowExpression
#apply_time, #attributes, #children, #environment_id, #fei, #parent_id, #raw_representation
Attributes included from Contextual
Instance Method Summary collapse
Methods included from ValueMixin
#apply, #lookup_field_attribute, #lookup_variable_attribute
Methods inherited from FlowExpression
#apply, #cancel, #clean_children, #delete_variable, #dup_environment, #fetch_environment, #fetch_text_content, #get_binding, #get_environment, #get_parent, #get_root_environment, #has_attribute, #initialize, is_definition, is_definition?, #lookup_attribute, #lookup_attributes, #lookup_boolean_attribute, #lookup_comma_list_attribute, #lookup_downcase_attribute, #lookup_ref, #lookup_string_attribute, #lookup_sym_attribute, #lookup_value, #lookup_variable, #lookup_vf_attribute, names, #new_environment, new_exp, #owns_its_environment?, #paused?, #remove_child, #reply_to_parent, #set_variable, #store_itself, #synchronize, #to_s, #to_yaml_properties
Methods included from Contextual
#get_work_directory, #init_service, #lookup
Methods included from Logging
#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn
Methods included from OwfeServiceLocator
#get_engine, #get_error_journal, #get_expool, #get_expression_map, #get_expression_pool, #get_expression_storage, #get_expression_storages, #get_journal, #get_participant_map, #get_scheduler, #get_wfid_generator
Methods inherited from ObjectWithMeta
#class_def, meta_def, meta_eval, metaclass
Constructor Details
This class inherits a constructor from OpenWFE::FlowExpression
Instance Method Details
#reply(workitem) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/openwfe/expressions/fe_misc.rb', line 147 def reply (workitem) raise "evaluation of ruby code is not allowed" \ if @application_context[:ruby_eval_allowed] != true code = lookup_vf_attribute(workitem, 'code') || workitem.get_result code = code.to_s wi = workitem # so that the ruby code being evaluated sees 'wi' and 'workitem' result = Rufus::eval_safely code, SAFETY_LEVEL, binding() workitem.set_result(result) \ if result != nil # 'false' is a valid result reply_to_parent workitem end |