lib/openwfe/flowexpressionid.rb in openwferu-0.9.16 vs lib/openwfe/flowexpressionid.rb in openwferu-0.9.17

- old
+ new

@@ -1,8 +1,8 @@ # #-- -# Copyright (c) 2005-2007, John Mettraux, OpenWFE.org +# Copyright (c) 2005-2008, John Mettraux, OpenWFE.org # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # @@ -65,24 +65,34 @@ :expression_id ] FIELDS.each { |f| attr_accessor f } - # - # A shortcut for fei.workflow_instance_id. - # There's also fei.parent_wfid. - # - alias :wfid :workflow_instance_id - alias :wfid= :workflow_instance_id= alias :expid :expression_id alias :expid= :expression_id= alias :expname :expression_name + alias :wfurl :workflow_definition_url alias :wfname :workflow_definition_name alias :wfrevision :workflow_definition_revision # + # This method return @workflow_instance_id. If parent is set to + # true, if will return the same result as + # parent_workflow_instance_id(). + # + def wfid (parent=false) + + if parent + parent_workflow_instance_id + else + workflow_instance_id + end + end + alias :wfid= :workflow_instance_id= + + # # the old 'initial_engine_id' is now deprecated, the methods # are still around though. # def initial_engine_id= (s) @@ -95,36 +105,35 @@ # # Overrides the classical to_s() # def to_s - "(fei #{@owfe_version} #{@engine_id} #{@workflow_definition_url} #{@workflow_definition_name} #{@workflow_definition_revision} #{@workflow_instance_id} #{@expression_name} #{@expression_id})" + "(fei #{@owfe_version} #{@engine_id} #{wfurl} #{wfname} #{wfrevision} #{wfid} #{expname} #{expid})" end # # Returns a hash version of this FlowExpressionId instance. # def to_h - h = {} - FIELDS.each { |f| h[f] = instance_eval("@#{f.to_s}") } - h + FIELDS.inject({}) { |r, f| r[f] = instance_eval("@#{f.to_s}"); r } end # # Rebuilds a FlowExpressionId from its Hash representation. # def FlowExpressionId.from_h (h) - fei = FlowExpressionId.new - FIELDS.each { |f| fei.instance_variable_set("@#{f}", h[f]) } - fei + FIELDS.inject FlowExpressionId.new do |fei, f| + fei.instance_variable_set("@#{f}", h[f] || h[f.to_s]) + fei + end end - def hash () + def hash - to_s().hash() + to_s.hash end def == (other) return false if not other.kind_of?(FlowExpressionId) @@ -176,18 +185,18 @@ end alias eql? == def to_debug_s - "(fei #{@workflow_definition_name} #{@workflow_definition_revision} #{@workflow_instance_id} #{@expression_id} #{@expression_name})" + "(fei #{wfname} #{wfrevision} #{wfid} #{expid} #{expname})" end # # Returns a very short string representation (fei wfid expid expname). # def to_short_s - "(fei #{@workflow_instance_id} #{@expression_id} #{@expression_name})" + "(fei #{wfid} #{expid} #{expname})" end # # Returns a URI escaped string with just the wfid and the expid, like # '20070917-dupibodasa__0.0.1' @@ -195,14 +204,26 @@ # Useful for unique identifier in URIs. # def to_web_s eid = expid.gsub("\.", "_") - URI.escape("#{workflow_instance_id}__#{eid}") + + URI.escape "#{wfid}__#{eid}" end # + # Splits the web fei into the workflow instance id and the expression + # id. + # + def self.split_web_s (s) + + i = s.rindex("__") + + [ s[0..i-1], s[i+2..-1].gsub("\_", ".") ] + end + + # # Yet another debugging method. Just returns the sub_instance_id and # the expression_id, in a string. # def to_env_s @@ -214,13 +235,11 @@ # For example, if the wfid is "1234.0.1", this method will # return "1234". # def parent_workflow_instance_id - i = workflow_instance_id.index(".") - return workflow_instance_id unless i - workflow_instance_id[0..i-1] + FlowExpressionId.to_parent_wfid workflow_instance_id end alias :parent_wfid :parent_workflow_instance_id # @@ -312,9 +331,20 @@ # An alias for to_fei(string) # def self.from_s (string) to_fei string + end + + # + # If wfid is already a 'parent wfid' (no sub id), returns it. Else + # returns the parent wfid (whatever is before the first "."). + # + def self.to_parent_wfid (wfid) + + i = wfid.index(".") + return wfid unless i + wfid[0..i-1] end end end