Class: Compass::Notification::Provider
- Inherits:
-
Object
- Object
- Compass::Notification::Provider
- Defined in:
- lib/compass/notification/provider.rb
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #fetch_notifications ⇒ Object
- #format_notification(notification) ⇒ Object
-
#initialize(**context) ⇒ Provider
constructor
Instance methods.
- #label ⇒ Object
- #retrieve_notifications ⇒ Object
- #updated_at ⇒ Object
Constructor Details
#initialize(**context) ⇒ Provider
Instance methods
29 30 31 32 |
# File 'lib/compass/notification/provider.rb', line 29 def initialize(**context) @context = context context.each { |key, value| define_singleton_method(key) { value } } end |
Class Method Details
.global_notifications(context = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/compass/notification/provider.rb', line 15 def global_notifications(context = {}) Compass.config.notification.providers.map do |provider| begin provider_class = provider.try(:constantize) || provider provider_class.new(**context) rescue => e Compass.logger&.error("[ Compass::Notification::Provider ] #{provider}: #{e.class}: #{e.}") nil end end end |
Instance Method Details
#as_json(options = {}) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/compass/notification/provider.rb', line 57 def as_json( = {}) { label: label, notifications: Array(fetch_notifications).map { |notification| format_notification(notification) }.compact } end |
#fetch_notifications ⇒ Object
34 35 36 37 38 39 |
# File 'lib/compass/notification/provider.rb', line 34 def fetch_notifications retrieve_notifications rescue => e log_error(e) [] end |
#format_notification(notification) ⇒ Object
45 46 47 |
# File 'lib/compass/notification/provider.rb', line 45 def format_notification(notification) raise NotImplementedError, "#{self.class} must implement #format_notification" end |
#label ⇒ Object
49 50 51 |
# File 'lib/compass/notification/provider.rb', line 49 def label raise NotImplementedError, "#{self.class} must implement #label" end |
#retrieve_notifications ⇒ Object
41 42 43 |
# File 'lib/compass/notification/provider.rb', line 41 def retrieve_notifications raise NotImplementedError, "#{self.class} must implement #retrieve_notifications" end |
#updated_at ⇒ Object
53 54 55 |
# File 'lib/compass/notification/provider.rb', line 53 def updated_at raise NotImplementedError, "#{self.class} must implement #updated_at" end |