Class: Ruote::FlowExpressionId
- Inherits:
-
Object
- Object
- Ruote::FlowExpressionId
- 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 collapse
- CHILD_SEP =
'_'
- SUBS =
%w[ subid sub_wfid ]
- IDS =
%w[ engine_id expid wfid ]
Instance Attribute Summary collapse
-
#h ⇒ Object
readonly
Returns the value of attribute h.
Class Method Summary collapse
-
.child_id(h) ⇒ Object
Returns child_id…
-
.direct_child?(parent_fei, other_fei) ⇒ Boolean
Returns true if other_fei is the fei of a child expression of parent_fei.
-
.extract(arg) ⇒ Object
Attempts at extracting a FlowExpressionId from the given argument (workitem, string, …).
-
.extract_h(arg) ⇒ Object
Attempts at extracting a FlowExpressionId (as a Hash instance) from the given argument (workitem, string, …).
-
.from_id(s, engine_id = 'engine') ⇒ Object
Turns the result of to_storage_id back to a FlowExpressionId instance.
-
.is_a_fei?(h) ⇒ Boolean
Returns true if the h is a representation of a FlowExpressionId instance.
- .to_storage_id(hfei) ⇒ Object
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
For proper hashing and sorting.
-
#==(other) ⇒ Object
(also: #eql?)
Returns true if the other is a FlowExpressionId instance and it points to the same expression as this one.
-
#child_id ⇒ Object
Returns the last number in the expid.
- #engine_id ⇒ Object
- #expid ⇒ Object
-
#hash ⇒ Object
For proper hashing and sorting.
-
#initialize(h) ⇒ FlowExpressionId
constructor
A new instance of FlowExpressionId.
-
#mnemo_id ⇒ Object
Returns a rufus-mnemo version of the first 9 hexdigits in the subid.
-
#short_sid ⇒ Object
expid!subid[0, 5]!wfid.
- #sid ⇒ Object
- #subid ⇒ Object (also: #sub_wfid)
- #to_h ⇒ Object
-
#to_sortable_id ⇒ Object
wfid!!expid.
- #to_storage_id ⇒ Object
- #wfid ⇒ Object
Constructor Details
#initialize(h) ⇒ FlowExpressionId
Returns a new instance of FlowExpressionId.
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ruote/fei.rb', line 124 def initialize(h) @h = h class << h; include Ruote::HashDot; end sub_wfid = @h.delete('sub_wfid') @h['subid'] ||= sub_wfid # # TODO : for 2.2.2, remove those two lines end |
Instance Attribute Details
#h ⇒ Object (readonly)
Returns the value of attribute h.
122 123 124 |
# File 'lib/ruote/fei.rb', line 122 def h @h end |
Class Method Details
.child_id(h) ⇒ Object
Returns child_id… For an expid of ‘0_1_4’, this will be 4.
232 233 234 235 |
# File 'lib/ruote/fei.rb', line 232 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.
245 246 247 248 249 250 251 252 253 254 |
# File 'lib/ruote/fei.rb', line 245 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
261 262 263 264 |
# File 'lib/ruote/fei.rb', line 261 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, …)
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/ruote/fei.rb', line 269 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 |
.from_id(s, engine_id = 'engine') ⇒ Object
Turns the result of to_storage_id back to a FlowExpressionId instance.
174 175 176 177 |
# File 'lib/ruote/fei.rb', line 174 def self.from_id(s, engine_id='engine') extract("#{engine_id}!#{s}") end |
.is_a_fei?(h) ⇒ Boolean
Returns true if the h is a representation of a FlowExpressionId instance.
225 226 227 228 |
# File 'lib/ruote/fei.rb', line 225 def self.is_a_fei?(h) h.respond_to?(:keys) && (h.keys - SUBS).sort == IDS end |
.to_storage_id(hfei) ⇒ Object
163 164 165 166 167 168 169 170 |
# File 'lib/ruote/fei.rb', line 163 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
#<=>(other) ⇒ Object
For proper hashing and sorting.
203 204 205 206 |
# File 'lib/ruote/fei.rb', line 203 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.
211 212 213 214 215 216 |
# File 'lib/ruote/fei.rb', line 211 def ==(other) return false unless other.is_a?(Ruote::FlowExpressionId) (hash == other.hash) end |
#child_id ⇒ Object
Returns the last number in the expid. For instance, if the expid is ‘0_5_7’, the child_id will be ‘7’.
182 183 184 185 |
# File 'lib/ruote/fei.rb', line 182 def child_id h.expid.split(CHILD_SEP).last.to_i end |
#engine_id ⇒ Object
137 |
# File 'lib/ruote/fei.rb', line 137 def engine_id; @h['engine_id']; end |
#expid ⇒ Object
135 |
# File 'lib/ruote/fei.rb', line 135 def expid; @h['expid']; end |
#hash ⇒ Object
For proper hashing and sorting.
196 197 198 199 |
# File 'lib/ruote/fei.rb', line 196 def hash to_storage_id.hash end |
#mnemo_id ⇒ Object
Returns a rufus-mnemo version of the first 9 hexdigits in the subid.
189 190 191 192 |
# File 'lib/ruote/fei.rb', line 189 def mnemo_id Rufus::Mnemo.from_i(@h['subid'][0, 9].to_i(16)) end |
#short_sid ⇒ Object
expid!subid[0, 5]!wfid
151 152 153 154 |
# File 'lib/ruote/fei.rb', line 151 def short_sid "#{@h['expid']}!#{@h['subid'][0, 5]}!#{@h['wfid']}" end |
#sid ⇒ Object
147 148 149 150 |
# File 'lib/ruote/fei.rb', line 147 def to_storage_id "#{@h['expid']}!#{@h['subid']}!#{@h['wfid']}" end |
#subid ⇒ Object Also known as: sub_wfid
138 |
# File 'lib/ruote/fei.rb', line 138 def subid; @h['subid']; end |
#to_h ⇒ Object
237 238 239 240 |
# File 'lib/ruote/fei.rb', line 237 def to_h @h end |
#to_sortable_id ⇒ Object
wfid!!expid
158 159 160 161 |
# File 'lib/ruote/fei.rb', line 158 def to_sortable_id "#{@h['wfid']}!!#{@h['expid']}" end |
#to_storage_id ⇒ Object
142 143 144 145 |
# File 'lib/ruote/fei.rb', line 142 def to_storage_id "#{@h['expid']}!#{@h['subid']}!#{@h['wfid']}" end |
#wfid ⇒ Object
136 |
# File 'lib/ruote/fei.rb', line 136 def wfid; @h['wfid']; end |