Class: Ruote::FlowExpressionId

Inherits:
Object
  • Object
show all
Defined in:
lib/ruote/fei.rb

Overview

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.

Feis can thus indicate the position of a workitem in a process tree.

Feis contain four pieces of information :

  • wfid : workflow instance id, the identifier for the process instance

  • subid : a unique identifier for expressions (useful in loops)

  • expid : the expression id, where in the process tree

  • engine_id : only relevant in multi engine scenarii (defaults to 'engine')

Constant Summary

CHILD_SEP =
'_'
SUBS =
%w[ subid sub_wfid ]
IDS =
%w[ engine_id expid wfid ]

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (FlowExpressionId) initialize(h)

A new instance of FlowExpressionId



107
108
109
110
111
112
113
114
# File 'lib/ruote/fei.rb', line 107

def initialize(h)

  @h = h
  class << h; include Ruote::HashDot; end

  @h['subid'] = @h.delete('sub_wfid') if @h['sub_wfid']
    # TODO : for 2.1.13, remove this
end

Instance Attribute Details

- (Object) h (readonly)

Returns the value of attribute h



105
106
107
# File 'lib/ruote/fei.rb', line 105

def h
  @h
end

Class Method Details

+ (Object) child_id(h)

Returns child_id… For an expid of '0_1_4', this will be 4.



181
182
183
184
# File 'lib/ruote/fei.rb', line 181

def self.child_id(h)

  h['expid'].split(CHILD_SEP).last.to_i
end

+ (Boolean) direct_child?(parent_fei, other_fei)

Returns true if other_fei is the fei of a child expression of parent_fei.

Returns:

  • (Boolean)


194
195
196
197
198
199
200
201
202
203
# File 'lib/ruote/fei.rb', line 194

def self.direct_child?(parent_fei, other_fei)

  %w[ 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(CHILD_SEP)

  (pei == parent_fei['expid'])
end

+ (Object) extract(arg)

Attempts at extracting a FlowExpressionId from the given argument (workitem, string, …)

Uses .extract_h



210
211
212
213
# File 'lib/ruote/fei.rb', line 210

def self.extract(arg)

  FlowExpressionId.new(extract_h(arg))
end

+ (Object) extract_h(arg)

Attempts at extracting a FlowExpressionId (as a Hash instance) from the given argument (workitem, string, …)

Raises:

  • (ArgumentError)


218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/ruote/fei.rb', line 218

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],
      'subid' => ss[-2],
      'wfid' => ss[-1] }
  end

  raise ArgumentError.new(
    "couldn't extract fei out of instance of #{arg.class}")
end

+ (Object) from_id(s, engine_id = 'engine')

Turns the result of to_storage_id back to a FlowExpressionId instance.



139
140
141
142
# File 'lib/ruote/fei.rb', line 139

def self.from_id(s, engine_id='engine')

  extract("#{engine_id}!#{s}")
end

+ (Boolean) is_a_fei?(h)

Returns true if the h is a representation of a FlowExpressionId instance.

Returns:

  • (Boolean)


174
175
176
177
# File 'lib/ruote/fei.rb', line 174

def self.is_a_fei?(h)

  h.respond_to?(:keys) && (h.keys - SUBS).sort == IDS
end

+ (Object) to_storage_id(hfei)



128
129
130
131
132
133
134
135
# File 'lib/ruote/fei.rb', line 128

def self.to_storage_id(hfei)

  hfei.respond_to?(:to_storage_id) ?
    hfei.to_storage_id :
    "#{hfei['expid']}!#{hfei['subid'] || hfei['sub_wfid']}!#{hfei['wfid']}"

  # TODO : for 2.1.13, remove the subid || sub_wfid trick
end

Instance Method Details

- (Object) ==(other) Also known as: eql?

Returns true if the other is a FlowExpressionId instance and it points to the same expression as this one.



160
161
162
163
164
165
# File 'lib/ruote/fei.rb', line 160

def ==(other)

  return false unless other.is_a?(Ruote::FlowExpressionId)

  (hash == other.hash)
end

- (Object) child_id

Returns the last number in the expid. For instance, if the expid is '0_5_7', the child_id will be '7'.



147
148
149
150
# File 'lib/ruote/fei.rb', line 147

def child_id

  h.expid.split(CHILD_SEP).last.to_i
end

- (Object) engine_id



118
# File 'lib/ruote/fei.rb', line 118

def engine_id; @h['engine_id']; end

- (Object) expid



116
# File 'lib/ruote/fei.rb', line 116

def expid; @h['expid']; end

- (Object) hash



152
153
154
155
# File 'lib/ruote/fei.rb', line 152

def hash

  to_storage_id.hash
end

- (Object) sid



126
127
128
# File 'lib/ruote/fei.rb', line 126

def to_storage_id
  "#{@h['expid']}!#{@h['subid']}!#{@h['wfid']}"
end

- (Object) subid Also known as: sub_wfid



119
# File 'lib/ruote/fei.rb', line 119

def subid; @h['subid']; end

- (Object) to_h



186
187
188
189
# File 'lib/ruote/fei.rb', line 186

def to_h

  @h
end

- (Object) to_storage_id



123
124
125
# File 'lib/ruote/fei.rb', line 123

def to_storage_id
  "#{@h['expid']}!#{@h['subid']}!#{@h['wfid']}"
end

- (Object) wfid



117
# File 'lib/ruote/fei.rb', line 117

def wfid; @h['wfid']; end