Class: Activity::TypeRulesUpdatedHandler
- Inherits:
-
Object
- Object
- Activity::TypeRulesUpdatedHandler
- Defined in:
- app/subscribers/activity/type_rules_updated_handler.rb
Overview
Executes ActivityTypeRules with source_event_completion / source_event_cancellation
scope after an activity's result_type changes and the transaction commits.
Subscribes to: Events::ActivityUpdated
Guards on event.data[:activity_result_type_id_changed] (captured at callback
time from dirty tracking before the transaction closed) so we don't fire rules
on every update — only when the activity was completed or cancelled.
NOTE: a no-op when the activity has no activity_type or no result type.
Instance Method Summary collapse
Instance Method Details
#call(event) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/subscribers/activity/type_rules_updated_handler.rb', line 14 def call(event) return unless event.data[:activity_result_type_id_changed] activity = Activity.find_by(id: event.data[:activity_id]) return unless activity return unless activity.activity_type return unless activity.activity_result_type completion_rules = activity.activity_type.activity_type_rules .includes(:target_activity_type) .source_event_completion completion_rules.each { |r| r.execute_target_event_for_activity(activity) } cancellation_rules = activity.activity_type.activity_type_rules .includes(:target_activity_type) .source_event_cancellation cancellation_rules.each { |r| r.execute_target_event_for_activity(activity) } end |