Module: Wonkavision::Plugins::BusinessActivity::ClassMethods
- Defined in:
- lib/wonkavision/plugins/business_activity.rb
Instance Method Summary collapse
- #correlate_by(*args) ⇒ Object
- #create_binding(name, handler, *args) ⇒ Object
- #event(name, *args, &block) ⇒ Object
- #instantiate_handler(event_context) ⇒ Object
Instance Method Details
#correlate_by(*args) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/wonkavision/plugins/business_activity.rb', line 62 def correlate_by(*args) return {:model=>correlation_id_field, :event=>event_correlation_id_key} if args.blank? correlation = BusinessActivity.normalize_correlation_ids(*args) [:correlation_id_field] = correlation[:model] [:event_correlation_id_key] = correlation[:event] define_document_key correlation_id_field, String, :index=>true correlation_ids << correlation end |
#create_binding(name, handler, *args) ⇒ Object
74 75 76 |
# File 'lib/wonkavision/plugins/business_activity.rb', line 74 def create_binding(name,handler,*args) Wonkavision::Plugins::BusinessActivity::EventBinding.new(name,handler,*args) end |
#event(name, *args, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/wonkavision/plugins/business_activity.rb', line 42 def event(name,*args,&block) handle(name,args) do ctx = @wonkavision_event_context result = :ok if (block_given?) result = case block.arity when 3 then yield ctx.data,ctx.path,self when 2 then yield ctx.data, ctx.path when 1 then yield ctx.data else instance_eval &block end end unless result == :handled result = self.class.update_activity(self,ctx.data) unless result == :updated save! end result end end |
#instantiate_handler(event_context) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/wonkavision/plugins/business_activity.rb', line 33 def instantiate_handler(event_context) correlation = event_context.binding.correlation event_id = correlation ? (correlation[:event] || event_correlation_id_key) : event_correlation_id_key model_id = correlation ? (correlation[:model] || correlation_id_field) : correlation_id_field correlation_id = event_context.data[event_id.to_s] find_activity_instance(model_id,correlation_id) end |