lib/openwfe/expressions/condition.rb in openwferu-0.9.10.653 vs lib/openwfe/expressions/condition.rb in openwferu-0.9.11
- old
+ new
@@ -63,41 +63,23 @@
#
# This is the method brought to expression classes including this
# mixin. Easy evaluation of a conditon expressed in an attribute.
#
- def eval_condition (attname, workitem)
+ def eval_condition (attname, workitem, nattname=nil)
- #attname = pick_attribute(attname) \
- # if attname.is_a?(Array)
+ positive = nil
+ negative = nil
- conditional = lookup_attribute(attname, workitem)
- rconditional = lookup_attribute("r"+attname.to_s, workitem)
+ positive = do_eval_condition(attname, workitem)
+ negative = do_eval_condition(nattname, workitem) if nattname
- return do_eval(rconditional) \
- if rconditional and not conditional
+ negative = (not negative) if negative != nil
- return nil \
- unless conditional
+ return positive if positive != nil
- ldebug { "eval_condition() 0 for '#{conditional}'" }
-
- conditional = from_xml conditional
-
- ldebug { "eval_condition() 1 for '#{conditional}'" }
-
- begin
- return to_boolean(do_eval(conditional))
- rescue Exception => e
- # probably needs some quoting...
- end
-
- conditional = do_quote(conditional)
-
- ldebug { "eval_condition() 2 for '#{conditional}'" }
-
- to_boolean(do_eval(conditional))
+ negative
end
#
# Returns nil if the cited attname (without or without 'r' prefix)
# is not present.
@@ -119,9 +101,42 @@
nil
end
protected
+
+ def do_eval_condition (attname, workitem)
+
+ #attname = pick_attribute(attname) \
+ # if attname.is_a?(Array)
+
+ conditional = lookup_attribute(attname, workitem)
+ rconditional = lookup_attribute("r"+attname.to_s, workitem)
+
+ return do_eval(rconditional) \
+ if rconditional and not conditional
+
+ return nil \
+ unless conditional
+
+ ldebug { "do_eval_condition() 0 for '#{conditional}'" }
+
+ conditional = from_xml conditional
+
+ ldebug { "do_eval_condition() 1 for '#{conditional}'" }
+
+ begin
+ return to_boolean(do_eval(conditional))
+ rescue Exception => e
+ # probably needs some quoting...
+ end
+
+ conditional = do_quote(conditional)
+
+ ldebug { "do_eval_condition() 2 for '#{conditional}'" }
+
+ to_boolean(do_eval(conditional))
+ end
private
#
# Returns true if result is the "true" String or the true