lib/ruote/exp/fe_if.rb in ruote-2.1.11 vs lib/ruote/exp/fe_if.rb in ruote-2.2.0

- old
+ new

@@ -1,7 +1,7 @@ #-- -# Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com +# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell @@ -59,12 +59,19 @@ # participant :ref => 'Al', :if => '${f:customer} == British Petroleum' # # # == shorter # - # It's ok to shortcircuit the _if expression like this : + # The :test can be shortened to a :t : # + # _if :t => '${f:customer.name} == Fred' do + # subprocess 'premium_course' + # subprocess 'regular_course' + # end + # + # When using Ruby to generate the process definition tree, you can simply do : + # # _if '${f:customer.name} == Fred' do # subprocess 'premium_course' # subprocess 'regular_course' # end # @@ -77,45 +84,41 @@ reply(h.applied_workitem) end # called by 'else', 'then' or perhaps 'equals' # - def reply (workitem) + def reply(workitem) if workitem['fei'] == h.fei # apply --> reply h.test = attribute(:test) + h.test = attribute(:t) if h.test.nil? h.test = attribute_text if h.test.nil? h.test = nil if h.test == '' - offset = if h.test != nil - Condition.true?(h.test) ? 0 : 1 - else - 0 - end + offset = (h.test.nil? || Condition.true?(h.test)) ? 0 : 1 - apply_child_if_present(offset, workitem) + apply_child(offset, workitem) else # reply from a child if h.test != nil || Ruote::FlowExpressionId.child_id(workitem['fei']) != 0 reply_to_parent(workitem) else - apply_child_if_present( - workitem['fields']['__result__'] == true ? 1 : 2, workitem) + apply_child(workitem['fields']['__result__'] == true ? 1 : 2, workitem) end end end protected - def apply_child_if_present (index, workitem) + def apply_child(index, workitem) if tree_children[index] - apply_child(index, workitem) + super else reply_to_parent(workitem) end end end