lib/openwfe/expressions/fe_misc.rb in openwferu-0.9.10.653 vs lib/openwfe/expressions/fe_misc.rb in openwferu-0.9.11

- old
+ new

@@ -85,10 +85,36 @@ # # If the :ruby_eval_allowed isn't set to true # (<tt>engine.application_context[:ruby_eval_allowed] = true</tt>), 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... + # class RevalExpression < FlowExpression names :reval # @@ -97,32 +123,29 @@ # SAFETY_LEVEL = 3 def apply (workitem) - if @application_context[:ruby_eval_allowed] != true - #lwarn { "apply() :ruby_eval_allowed not set to true" } - #reply_to_parent(workitem) - #return - raise "evaluation of ruby code is not allowed" - end + raise "evaluation of ruby code is not allowed" \ + if @application_context[:ruby_eval_allowed] != true escape = lookup_boolean_attribute('escape', workitem, false) code = lookup_vf_attribute(workitem, 'code') code = fetch_text_content(workitem, escape) \ unless code code = code.to_s - #result = eval(code) - result = OpenWFE::eval_safely(code, SAFETY_LEVEL, binding()) + wi = workitem + result = OpenWFE::eval_safely code, SAFETY_LEVEL, binding() + workitem.set_result(result) \ if result != nil # 'false' is a valid result - reply_to_parent(workitem) + reply_to_parent workitem end end end