lib/openwfe/expressions/condition.rb in openwferu-0.9.7 vs lib/openwfe/expressions/condition.rb in openwferu-0.9.8
- old
+ new
@@ -59,21 +59,27 @@
# _break :if => "${f:approved}"
# end
#
module ConditionMixin
+ #
+ # 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)
+ #attname = pick_attribute(attname) \
+ # if attname.is_a?(Array)
+
conditional = lookup_attribute(attname, workitem)
rconditional = lookup_attribute("r"+attname.to_s, workitem)
- if rconditional and not conditional
- #return instance_eval(rconditional)
- return do_eval(rconditional)
- end
+ return do_eval(rconditional) \
+ if rconditional and not conditional
- return nil unless conditional
+ return nil \
+ unless conditional
#ldebug { "eval_condition() 0 for '#{conditional}'" }
conditional = from_xml(conditional)
@@ -88,9 +94,47 @@
ldebug { "eval_condition() 3 result is '#{result}'" }
return (result == "true" or result == true)
end
+
+ #
+ # Returns nil if the cited attname (without or without 'r' prefix)
+ # is not present.
+ #
+ # Attname may be a String or a Symbol, or an Array of String or Symbol
+ # instances.
+ #
+ # Returns the Symbol the attribute if present.
+ #
+ def determine_condition_attribute (attname)
+
+ attname = [ attname ] unless attname.is_a?(Array)
+
+ attname.each do |aname|
+ aname = aname.intern if aname.is_a?(String)
+ return aname if has_attribute(aname)
+ return aname if has_attribute("r" + aname.to_s)
+ end
+
+ nil
+ end
+
+ protected
+
+ #
+ # If the attribute name is a list of attribute names, pick
+ # the first one present.
+ #
+ #def pick_attribute (attnames)
+ # attnames.each do |attname|
+ # return attname if has_attribute(attname)
+ # return attname if has_attribute("r" + attname.to_s)
+ # end
+ # return attnames[0]
+ # #
+ # # some kind of a default (for error messages)
+ #end
private
def from_xml (string)