Module: ActivityNotification::NotificationResilience
- Extended by:
- ActiveSupport::Concern
- Included in:
- Mailers::Helpers
- Defined in:
- lib/activity_notification/notification_resilience.rb
Overview
Provides resilient notification handling across different ORMs Handles missing notification scenarios gracefully without raising exceptions
Constant Summary collapse
- ORM_EXCEPTIONS =
Exception classes for different ORMs
{ active_record: 'ActiveRecord::RecordNotFound', mongoid: 'Mongoid::Errors::DocumentNotFound', dynamoid: 'Dynamoid::Errors::RecordNotFound' }.freeze
Class Method Summary collapse
-
.current_orm ⇒ Object
Module-level methods that delegate to class methods.
-
.record_not_found_exception?(exception) ⇒ Boolean
Checks if an exception is a “record not found” exception for any supported ORM.
-
.record_not_found_exception_class ⇒ Class
Returns the exception class for the current ORM.
Instance Method Summary collapse
-
#with_notification_resilience(notification_id = nil, context = {}) { ... } ⇒ Object?
Executes a block with resilient notification handling Catches ORM-specific “record not found” exceptions and logs them appropriately.
Class Method Details
.current_orm ⇒ Object
Module-level methods that delegate to class methods
17 18 19 |
# File 'lib/activity_notification/notification_resilience.rb', line 17 def current_orm ActivityNotification.config.orm end |
.record_not_found_exception?(exception) ⇒ Boolean
Checks if an exception is a “record not found” exception for any supported ORM
37 38 39 40 41 42 43 44 45 |
# File 'lib/activity_notification/notification_resilience.rb', line 37 def record_not_found_exception?(exception) ORM_EXCEPTIONS.values.any? do |exception_name| begin exception.is_a?(exception_name.constantize) rescue NameError false end end end |
.record_not_found_exception_class ⇒ Class
Returns the exception class for the current ORM
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/activity_notification/notification_resilience.rb', line 23 def record_not_found_exception_class exception_name = ORM_EXCEPTIONS[current_orm] return nil unless exception_name begin exception_name.constantize rescue NameError nil end end |
Instance Method Details
#with_notification_resilience(notification_id = nil, context = {}) { ... } ⇒ Object?
Executes a block with resilient notification handling Catches ORM-specific “record not found” exceptions and logs them appropriately
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/activity_notification/notification_resilience.rb', line 80 def with_notification_resilience(notification_id = nil, context = {}) yield rescue => exception if self.class.record_not_found_exception?(exception) log_missing_notification(notification_id, exception, context) nil else raise exception end end |