lib/openwfe/expressions/fe_misc.rb in openwferu-0.9.15 vs lib/openwfe/expressions/fe_misc.rb in openwferu-0.9.16

- old
+ new

@@ -41,43 +41,55 @@ require 'openwfe/expressions/flowexpression' module OpenWFE + # + # A debug/test expression (it's mostly used in the test suite + # used for the development of OpenWFEru). + # Outputs a message to the STDOUT (via the "puts" Ruby method). + # + # <print>hello</print> + # + # _print "hello" + # _print do + # "in a block" + # end + # + # Note that when expressing the process in Ruby, an underscore has to be + # placed in front of the expression name to avoid a collision with the + # Ruby 'print' function. + # + # If there is an object bound in the application context under the + # name '__tracer', this expression will append its message to this + # instance instead of emitting to the STDOUT. (this is how the + # OpenWFEru test suite uses this expression). + # class PrintExpression < FlowExpression names :print - # - # apply / reply - def apply (workitem) escape = lookup_boolean_attribute('escape', workitem, false) - text = fetch_text_content(workitem, escape) + text = fetch_text_content workitem, escape text << "\n" tracer = @application_context['__tracer'] if tracer tracer << text else puts text end - reply_to_parent(workitem) + reply_to_parent workitem end - - #def reply (workitem) - #end - end # - # <reval/> - # # Evals some Ruby code contained within the process definition # or within the workitem. # # The code is evaluated at a SAFE level of 3. # @@ -139,9 +151,56 @@ result = OpenWFE::eval_safely code, SAFETY_LEVEL, binding() workitem.set_result(result) \ if result != nil # 'false' is a valid result + + reply_to_parent workitem + end + end + + # + # This expression simply emits a message to the application + # log (by default logs/openwferu.log). + # + # <sequence> + # <log>before participant alpha</log> + # <participant ref="alpha" /> + # <log>after participant alpha</log> + # <log level="warn">after participant alpha</log> + # </sequence> + # + # And an example with a Ruby process definition : + # + # sequence do + # log "simple debug message" + # log do + # "another debug message" + # end + # log :message => "yet another debug message" + # log :message => "an info level message", :level => "info" + # end + # + # Possible log levels are 'debug' (the default), 'info', 'warn' and + # 'fatal'. + # + class LogExpression < FlowExpression + + names :log + + def apply (workitem) + + escape = lookup_boolean_attribute('escape', workitem, false) + text = fetch_text_content(workitem, escape) + text = lookup_attribute('message', workitem) unless text + + level = lookup_attribute('level', workitem) + level = level.downcase.to_sym if level + + level = :debug \ + unless [ :info, :warn, :error, :fatal ].include?(level) + + get_engine.llog(level, text) if text reply_to_parent workitem end end