lib/ruote/fei.rb in ruote-2.1.9 vs lib/ruote/fei.rb in ruote-2.1.10

- old
+ new

@@ -21,10 +21,11 @@ # # Made in Japan. #++ require 'ruote/version' +require 'ruote/workitem' require 'ruote/util/misc' require 'ruote/util/hashdot' module Ruote @@ -36,11 +37,20 @@ def self.to_storage_id (fei) Ruote::FlowExpressionId.to_storage_id(fei) end + # A shorter shortcut for # + # Ruote::FlowExpressionId.to_storage_id(fei) + # + def self.sid (fei) + + Ruote::FlowExpressionId.to_storage_id(fei) + end + + # # The FlowExpressionId (fei for short) is an process expression identifier. # Each expression when instantiated gets a unique fei. # # Feis are also used in workitems, where the fei is the fei of the # [participant] expression that emitted the workitem. @@ -76,25 +86,30 @@ def sub_wfid @h['sub_wfid'] end + def engine_id + @h['engine_id'] + end + def to_storage_id "#{@h['expid']}!#{@h['sub_wfid']}!#{@h['wfid']}" end def self.to_storage_id (hfei) - "#{hfei['expid']}!#{hfei['sub_wfid']}!#{hfei['wfid']}" + + hfei.respond_to?(:to_storage_id) ? + hfei.to_storage_id : + "#{hfei['expid']}!#{hfei['sub_wfid']}!#{hfei['wfid']}" end + # Turns the result of to_storage_id back to a FlowExpressionId instance. + # def self.from_id (s, engine_id='engine') - ss = s.split('!') - - FlowExpressionId.new( - 'engine_id' => engine_id, - 'expid' => ss[-3], 'sub_wfid' => ss[-2], 'wfid' => ss[-1]) + extract("#{engine_id}!#{s}") end # Returns the last number in the expid. For instance, if the expid is # '0_5_7', the child_id will be '7'. # @@ -137,12 +152,49 @@ %w[ sub_wfid wfid engine_id ].each do |k| return false if parent_fei[k] != other_fei[k] end - pei = other_fei['expid'].split(CHILD_SEP)[0..-2].join('_') + pei = other_fei['expid'].split(CHILD_SEP)[0..-2].join(CHILD_SEP) (pei == parent_fei['expid']) + end + + # Attempts at extracting a FlowExpressionId from the given argument + # (workitem, string, ...) + # + # Uses .extract_h + # + def self.extract (arg) + + FlowExpressionId.new(extract_h(arg)) + end + + # Attempts at extracting a FlowExpressionId (as a Hash instance) from the + # given argument (workitem, string, ...) + # + def self.extract_h (arg) + + if arg.is_a?(Hash) + return arg if arg['expid'] + return arg['fei'] if arg['fei'] + end + + return extract_h(arg.fei) if arg.respond_to?(:fei) + return arg.h if arg.is_a?(Ruote::FlowExpressionId) + return arg.h['fei'] if arg.is_a?(Ruote::Workitem) + + if arg.is_a?(String) + + ss = arg.split('!') + + return { + 'engine_id' => ss[-4] || 'engine', + 'expid' => ss[-3], 'sub_wfid' => ss[-2], 'wfid' => ss[-1] } + end + + raise ArgumentError.new( + "couldn't extract fei out of instance of #{arg.class}") end end end