Class: Ruote::FlowExpressionId

Inherits:
Object
  • Object
show all
Includes:
WithH
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 =
'_'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WithH

#h, #h=, included, #to_h

Constructor Details

#initialize(hash) ⇒ FlowExpressionId



68
69
70
71
72
73
74
75
76
# File 'lib/ruote/fei.rb', line 68

def initialize(hash)

  self.h = hash

  sub_wfid = h.delete('sub_wfid')
  h.subid ||= sub_wfid
    #
    # TODO : for 2.2.2, remove those two lines
end

Class Method Details

.child_id(h) ⇒ Object

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



164
165
166
167
# File 'lib/ruote/fei.rb', line 164

def self.child_id(h)

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

.direct_child?(parent_fei, other_fei) ⇒ Boolean

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



172
173
174
175
176
177
178
179
180
181
# File 'lib/ruote/fei.rb', line 172

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

.extract(arg) ⇒ Object

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

Uses .extract_h



188
189
190
191
# File 'lib/ruote/fei.rb', line 188

def self.extract(arg)

  FlowExpressionId.new(extract_h(arg))
end

.extract_h(arg) ⇒ Object

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

Raises:

  • (ArgumentError)


196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/ruote/fei.rb', line 196

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.to_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

.from_id(s, engine_id = 'engine') ⇒ Object

Turns the result of to_storage_id back to a FlowExpressionId instance.



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

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

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

.to_storage_id(hfei) ⇒ Object



103
104
105
106
107
108
109
110
111
112
# File 'lib/ruote/fei.rb', line 103

def self.to_storage_id(hfei)

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

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

Instance Method Details

#<=>(other) ⇒ Object

For proper hashing and sorting.



145
146
147
148
# File 'lib/ruote/fei.rb', line 145

def <=>(other)

  self.to_sortable_id <=> other.to_sortable_id
end

#==(other) ⇒ Object Also known as: eql?

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



153
154
155
156
157
158
# File 'lib/ruote/fei.rb', line 153

def ==(other)

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

  (hash == other.hash)
end

#child_idObject

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



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

def child_id

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

#hashObject

For proper hashing and sorting.



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

def hash

  to_storage_id.hash
end

#mnemo_idObject

Returns a rufus-mnemo version of the first 9 hexdigits in the subid.



131
132
133
134
# File 'lib/ruote/fei.rb', line 131

def mnemo_id

  Rufus::Mnemo.from_i(h.subid[0, 9].to_i(16))
end

#short_sidObject

expid!subid[0, 5]!wfid



91
92
93
94
# File 'lib/ruote/fei.rb', line 91

def short_sid

  [ expid, subid[0, 5], wfid ].join('!')
end

#sidObject



87
88
89
90
# File 'lib/ruote/fei.rb', line 87

def to_storage_id

  [ expid, subid, wfid ].join('!')
end

#to_sortable_idObject

wfid!!expid



98
99
100
101
# File 'lib/ruote/fei.rb', line 98

def to_sortable_id

  [ wfid, expid ].join('!!')
end

#to_storage_idObject



82
83
84
85
# File 'lib/ruote/fei.rb', line 82

def to_storage_id

  [ expid, subid, wfid ].join('!')
end