lib/openwfe/expressions/fe_value.rb in openwferu-0.9.13 vs lib/openwfe/expressions/fe_value.rb in openwferu-0.9.14

- old
+ new

@@ -27,10 +27,11 @@ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. #++ +# # # "made in Japan" # # John Mettraux at openwfe.org @@ -42,10 +43,39 @@ module OpenWFE # + # A small mixin providing value for looking up the attributes + # variable/var/v and field/fld/f. + # + module ValueMixin + + def lookup_variable_attribute (workitem) + + lookup [ "variable", "var", "v" ], workitem + end + + def lookup_field_attribute (workitem) + + lookup [ "field", "fld", "f" ], workitem + end + + private + + def lookup (name_array, workitem) + + name_array.each do |n| + v = lookup_attribute(n, workitem) + return v if v + end + + nil + end + end + + # # The 'set' expression is used to set the value of a (process) variable or # a (workitem) field. # # <set field="price" value="CHF 12.00" /> # <set variable="/stage" value="3" /> @@ -56,11 +86,22 @@ # # 'set' expressions may be placed outside of a process-definition body, # they will be evaluated sequentially before the body gets applied # (executed). # + # Since OpenWFEru 0.9.14, shorter attributes are OK : + # + # <set f="price" val="CHF 12.00" /> + # <set v="/stage" val="3" /> + # <set v="/stage" field-val="f_stage" /> + # <set f="stamp" val="${r:Time.now.to_i}" /> + # + # set :f => "price", :val => "USD 12.50" + # set :v => "toto", :val => "elvis" + # class SetValueExpression < FlowExpression + include ValueMixin is_definition names :set @@ -86,12 +127,12 @@ reply(workitem) end def reply (workitem) - vkey = lookup_attribute("variable", workitem) - fkey = lookup_attribute("field", workitem) + vkey = lookup_variable_attribute(workitem) + fkey = lookup_field_attribute(workitem) value = workitem.attributes[FIELD_RESULT] #puts "value is '#{value}'" @@ -127,16 +168,17 @@ # # unset :field => "price" # unset :variable => "eval_result" # class UnsetValueExpression < FlowExpression + include ValueMixin names :unset def apply (workitem) - vkey = lookup_attribute("variable", workitem) - fkey = lookup_attribute("field", workitem) + vkey = lookup_variable_attribute(workitem) + fkey = lookup_field_attribute(workitem) if vkey delete_variable(vkey) elsif fkey workitem.attributes.delete(fkey)