lib/openwfe/expressions/fe_value.rb in openwferu-0.9.2 vs lib/openwfe/expressions/fe_value.rb in openwferu-0.9.3

- old
+ new

@@ -41,10 +41,11 @@ require 'openwfe/workitem' require 'openwfe/flowexpressionid' require 'openwfe/expressions/flowexpression' require 'openwfe/expressions/fe_utils' +require 'openwfe/expressions/fe_condition' # # expressions like 'set' and 'unset' and their utility methods # @@ -185,23 +186,32 @@ # # <if/> # class IfExpression < FlowExpression + include ConditionMixin attr_accessor \ :condition_replied def apply (workitem) reply_to_parent(workitem) if @children.length < 1 - @condition_replied = false + test = eval_condition(:test, workitem) + @condition_replied = (test != nil) + # + # if the "test" attribute is not used, test will be null + store_itself() - get_expression_pool.apply(@children[0], workitem) + if test != nil + apply_consequence(test, workitem, 0) + else + get_expression_pool.apply(@children[0], workitem) + end end def reply (workitem) if @condition_replied @@ -213,24 +223,33 @@ @condition_replied = true store_itself() - if result - apply_consequence(1, workitem) - else - apply_consequence(2, workitem) - end + apply_consequence(result, workitem) end def reply_to_parent(workitem) clean_children() super(workitem) end protected - def apply_consequence (index, workitem) + def apply_consequence (index, workitem, offset=1) + + if index == true + index = 0 + elsif index == false + index = 1 + elsif index == nil + index = 1 + elsif not index.integer? + index = 0 + end + + index = index + offset + if index >= @children.length reply_to_parent(workitem) else get_expression_pool.apply(@children[index], workitem) end