Module OpenWFE::ConditionMixin
In: lib/openwfe/expressions/condition.rb

A ConditionMixin is a mixin for flow expressions like ‘if’ and ‘break’ for example. It allows for shorter notations like

    <if test="${f:approved} == true"/>

or

    _loop do
        participant :graphical_designer
        participant :business_analyst
        _break :if => "${f:approved}"
    end

Methods

Constants

SET_REGEX = /(\S*?)( is)?( not)? set$/

Public Instance methods

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.

[Source]

     # File lib/openwfe/expressions/condition.rb, line 90
 90:         def determine_condition_attribute (attname)
 91: 
 92:             attname = [ attname ] unless attname.is_a?(Array)
 93: 
 94:             attname.each do |aname|
 95:                 aname = aname.intern if aname.is_a?(String)
 96:                 return aname if has_attribute(aname)
 97:                 return aname if has_attribute("r" + aname.to_s)
 98:             end
 99: 
100:             nil
101:         end

This is the method brought to expression classes including this mixin. Easy evaluation of a conditon expressed in an attribute.

[Source]

    # File lib/openwfe/expressions/condition.rb, line 66
66:         def eval_condition (attname, workitem, nattname=nil)
67: 
68:             positive = nil
69:             negative = nil
70: 
71:             positive = do_eval_condition(attname, workitem)
72:             negative = do_eval_condition(nattname, workitem) if nattname
73: 
74:             negative = (not negative) if negative != nil
75: 
76:             return positive if positive != nil
77: 
78:             negative
79:         end

Protected Instance methods

[Source]

     # File lib/openwfe/expressions/condition.rb, line 105
105:             def do_eval_condition (attname, workitem)
106: 
107:                 #attname = pick_attribute(attname)                  #    if attname.is_a?(Array)
108: 
109:                 conditional = lookup_attribute(attname, workitem)
110:                 rconditional = lookup_attribute("r"+attname.to_s, workitem)
111: 
112:                 return do_eval(rconditional, workitem) \
113:                     if rconditional and not conditional
114: 
115:                 return nil \
116:                     unless conditional
117: 
118:                 ldebug { "do_eval_condition() 0 for  >#{conditional}<" }
119: 
120:                 conditional = unescape conditional
121: 
122:                 ldebug { "do_eval_condition() 1 for  >#{conditional}<" }
123: 
124:                 r = eval_set conditional
125:                 return r if r != nil
126: 
127:                 begin
128:                     return to_boolean(do_eval(conditional, workitem))
129:                 rescue Exception => e
130:                     # probably needs some quoting...
131:                     ldebug { "do_eval_condition() e : #{e}" }
132:                 end
133: 
134:                 conditional = do_quote(conditional)
135: 
136:                 ldebug { "do_eval_condition() 2 for  >#{conditional}<" }
137: 
138:                 to_boolean(do_eval(conditional, workitem))
139:             end

Evals the ‘x [ is][ not] set’ notation…

[Source]

     # File lib/openwfe/expressions/condition.rb, line 147
147:             def eval_set (cond)
148: 
149:                 m = SET_REGEX.match cond
150: 
151:                 return nil unless m
152: 
153:                 val = m[1]
154:                 n = m[3]
155: 
156:                 ldebug do 
157:                     "eval_set() for >#{cond}<  "+
158:                     "m[1] is '#{val}', m[3] is '#{n}'"
159:                 end
160: 
161:                 val = val.strip if val
162:                 val = (val != nil and val != '')
163:                 n = (n and n.strip == 'not')
164: 
165:                 n ? (not val) : val
166:             end

[Validate]