conditions

Conditions can be used with the :if and :unless common attributes and with the if, given, once and equals (though this one is rather obsolete).

With the :if common attribute:

              cursor do
                participant 'customer'
                rewind :if => '${not_enough_info} == true'
                participant 'logistics'
              end
            

With the given expression:

              given do
                that "${location} == paris" do
                  subprocess "notify_and_wait_for_pickup"
                end
                that "${state} == ready" do
                  subprocess "deliver"
                end
                # else...
                subprocess "do_something_else"
              end
            

As one can see, the conditions are tributary to the dollar notation.

what gets in the condition

After the string has completed all the dollar substitutions (yes, they can be nested), the resulting string is evaluated as a condition.

Without an operator, something not empty or not equal to the string “false” is considered true.

With an operator (==, >=, >, etc) the comparison is evaluated. Ruote understands the same operators as Ruby plus a few others.

Thus, with

              bill :if => '${amount} > 0.0'
            

if the workitem field amount contains 5.0, the condition becomes

              bill :if => '5.0 > 0.0'
            

and this result “5.0 > 0.0” string is then evaluated as a condition. All dollar substitutions are performed before the check for a condition.

without an operator

Without an operator (something like == or <), a condition holds true if the resulting string, when stripped, is not empty (length > 0) and not equal to the string “false”.

              bill :if => '${amount}'
            

The bill participant (or subprocess) will be triggered if the workitem field “amount” when turned to a string result in something non-empty and not equal to the “false” string.

with an operator

              notify_boss :if => '${amount} == 12.0'
              bill :if => '${amount} != 0.0'
              bill :if => '${amount} > 0.0'
              notify_boss :if => '${customer.name} =~ /^Acme /'
            

etc.

a note about strings

When dealing with strings, try to cut ambiguity. Surround the string with quotes or double-quotes or use the quoting thing of the dollar notation.

            bill :if =>
              "${amount} > 0.0 or (${'f:name} =~ /^Acme/ and ${'f:city} == 'Orlando')"
            

and / or combinations

One can use “and” and “&&”, and “or” and “||”. The regular Ruby precedence applies (‘and’ and ‘or’ have the same low precedence while ‘||’ has higher precedence and ‘&&’ tops them all).

              notify_boss :if => "${amount} > 500.0 and '${customer.name}' =~ /^Acme"
            

Using parenthesis is OK.

            bill :if =>
              "${amount} > 0.0 or (${'f:name} =~ /^Acme/ and ${'f:city} == 'Orlando')"
            

is set, is empty, is null, is in [ red, yellow ]

Ruote understands four special words preceded by an optional ‘is [not]’. Those words are ‘set’, ‘empty’, ‘null’ and ‘in’. The latter, ‘in’, is meant to be followed by an array.

Here are a few examples, they should be straightforward:

              notify :if => '${im_account} set'
              notify :if => '${im_account} is set'
            
              emit_mailing :if => '${emails} is not empty'
            
              review :if => '${document_uri} is not null'
            
              stop :if => '${signal} is in [ red, yellow ]'
            

The ‘is’ is optional.

falling back to Ruby

If ruote was configured with ‘ruby_eval_allowed’ => true, it’s OK to use ${r:…} and have ruby code decide.

              notify :if => '${r: rand > 0.5 }'
            

see also