Class: Factor::Runtime::Message
- Inherits:
-
Object
- Object
- Factor::Runtime::Message
- Defined in:
- lib/runtime/message.rb
Instance Attribute Summary collapse
-
#activity_instance_id ⇒ Object
Returns the value of attribute activity_instance_id.
-
#body ⇒ Object
Returns the value of attribute body.
-
#last_activity_instance_id ⇒ Object
Returns the value of attribute last_activity_instance_id.
-
#position ⇒ Object
Returns the value of attribute position.
-
#workflow ⇒ Object
Returns the value of attribute workflow.
-
#workflow_instance_id ⇒ Object
Returns the value of attribute workflow_instance_id.
Instance Method Summary collapse
- #add_values(values) ⇒ Object
- #from_queue(routing_key, payload) ⇒ Object
-
#initialize ⇒ Message
constructor
A new instance of Message.
- #payload ⇒ Object
- #respond(params, event) ⇒ Object
- #route ⇒ Object
Constructor Details
#initialize ⇒ Message
Returns a new instance of Message.
8 9 10 11 12 13 |
# File 'lib/runtime/message.rb', line 8 def initialize @activity_instance_id=SecureRandom.hex @workflow = workflow @body = Hash.new @position = Array.new end |
Instance Attribute Details
#activity_instance_id ⇒ Object
Returns the value of attribute activity_instance_id.
7 8 9 |
# File 'lib/runtime/message.rb', line 7 def activity_instance_id @activity_instance_id end |
#body ⇒ Object
Returns the value of attribute body.
7 8 9 |
# File 'lib/runtime/message.rb', line 7 def body @body end |
#last_activity_instance_id ⇒ Object
Returns the value of attribute last_activity_instance_id.
7 8 9 |
# File 'lib/runtime/message.rb', line 7 def last_activity_instance_id @last_activity_instance_id end |
#position ⇒ Object
Returns the value of attribute position.
7 8 9 |
# File 'lib/runtime/message.rb', line 7 def position @position end |
#workflow ⇒ Object
Returns the value of attribute workflow.
7 8 9 |
# File 'lib/runtime/message.rb', line 7 def workflow @workflow end |
#workflow_instance_id ⇒ Object
Returns the value of attribute workflow_instance_id.
7 8 9 |
# File 'lib/runtime/message.rb', line 7 def workflow_instance_id @workflow_instance_id end |
Instance Method Details
#add_values(values) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/runtime/message.rb', line 29 def add_values(values) current=@body position.each do |key| #puts "[add value] #{key} (#{key.class.name})" current[key]={} if !current.include?(key) current=current[key] end values.each do |key,value| current[key]=value end end |
#from_queue(routing_key, payload) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/runtime/message.rb', line 50 def from_queue routing_key, payload routing_array=routing_key.split('.') @workflow=routing_array.first #first @position=routing_array.drop(1) # everything after first =JSON.parse(payload) @body=["body"] @workflow_instance_id=["workflow_instance_id"] @activity_instance_id=["activity_instance_id"] @last_activity_instance_id=["last_activity_instance_id"] end |
#payload ⇒ Object
46 47 48 |
# File 'lib/runtime/message.rb', line 46 def payload {"body"=>@body, "workflow_instance_id"=>@workflow_instance_id, "activity_instance_id"=>@activity_instance_id, "last_activity_instance_id"=>@last_activity_instance_id}.to_json end |
#respond(params, event) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/runtime/message.rb', line 15 def respond(params, event) m = Message.new m.body = @body m.workflow_instance_id=@workflow_instance_id m.last_activity_instance_id = @activity_instance_id m.workflow = @workflow m.position = @position m.position << "on" m.position << event m.add_values(params) m end |
#route ⇒ Object
42 43 44 |
# File 'lib/runtime/message.rb', line 42 def route "#{workflow}.#{position.join('.')}" end |