Object
A workitem can be thought of an "execution token", but with a payload (fields).
The payload/fields MUST be JSONifiable.
# File lib/ruote/workitem.rb, line 42 def initialize (h) @h = h class << @h; include Ruote::HashDot; end #class << @h['fields'] # alias_method :__get, :[] # alias_method :__set, :[]= # def [] (key) # __get(key.to_s) # end # def []= (key, value) # __set(key.to_s, value) # end #end # indifferent access, not activated for now end
Warning : equality is based on fei and not on payload !
# File lib/ruote/workitem.rb, line 154 def == (other) return false if other.class != self.class self.h['fei'] == other.h['fei'] end
When was this workitem dispatched ?
# File lib/ruote/workitem.rb, line 147 def dispatch_at fields['dispatched_at'] end
Returns a complete copy of this workitem.
# File lib/ruote/workitem.rb, line 96 def dup Workitem.new(Rufus::Json.dup(@h)) end
Shortcut for wi.fields
# File lib/ruote/workitem.rb, line 217 def error @h['fields']['__error__'] end
Returns a Ruote::FlowExpressionId instance.
# File lib/ruote/workitem.rb, line 89 def fei FlowExpressionId.new(h.fei) end
Returns the payload, ie the fields hash.
# File lib/ruote/workitem.rb, line 112 def fields @h['fields'] end
Sets all the fields in one sweep.
Remember : the fields must be a JSONifiable hash.
# File lib/ruote/workitem.rb, line 121 def fields= (fields) @h['fields'] = fields end
Warning : hash is fei's hash.
# File lib/ruote/workitem.rb, line 164 def hash self.h['fei'].hash end
For a simple key
workitem.lookup('toto')
is equivalent to
workitem.fields['toto']
but for a complex key
workitem.lookup('toto.address')
is equivalent to
workitem.fields['toto']['address']
# File lib/ruote/workitem.rb, line 185 def lookup (key, container_lookup=false) Ruote.lookup(@h['fields'], key, container_lookup) end
Shortcut for wi.fields
When a participant is invoked like in
participant :ref => 'toto', :task => 'x"
then
p workitem.params
# => { 'ref' => 'toto', 'task' => 'x' }
# File lib/ruote/workitem.rb, line 233 def params @h['fields']['params'] end
The participant for which this item is destined. Will be nil when the workitem is transiting inside of its process instance (as opposed to when it's being delivered outside of the engine).
# File lib/ruote/workitem.rb, line 105 def participant_name @h['participant_name'] end
A shortcut to the value in the field named __result__
This field is used by the if expression for instance to determine if it should branch to its 'then' or its 'else'.
# File lib/ruote/workitem.rb, line 131 def result fields['__result__'] end
Sets the value of the 'special' field __result__
See result
# File lib/ruote/workitem.rb, line 140 def result= (r) fields['__result__'] = r end
Like lookup allows for nested lookups, set_field can be used to set sub fields directly.
workitem.set_field('customer.address.city', 'Pleasantville')
Warning : if the customer and address field and subfield are not present or are not hashes, set_field will simply create a "customer.address.city" field and set its value to "Pleasantville".
# File lib/ruote/workitem.rb, line 203 def set_field (key, value) Ruote.set(@h['fields'], key, value) end
Returns the String id for this workitem (something like "0_0!!20100507-wagamama").
It's in fact a shortcut for
Ruote::FlowExpressionId.to_storage_id(h.fei)
# File lib/ruote/workitem.rb, line 74 def sid Ruote::FlowExpressionId.to_storage_id(h.fei) end
Shortcut for wi.fields
# File lib/ruote/workitem.rb, line 210 def timed_out @h['fields']['__timed_out__'] end
Generated with the Darkfish Rdoc Generator 2.