Class: Compass::Notification::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/compass/notification/provider.rb

Class Method Summary collapse

Instance Method Summary collapse

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.message}")
      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(options = {})
  {
    label: label,
    notifications: Array(fetch_notifications).map { |notification| format_notification(notification) }.compact
  }
end

#fetch_notificationsObject



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

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/compass/notification/provider.rb', line 45

def format_notification(notification)
  raise NotImplementedError, "#{self.class} must implement #format_notification"
end

#labelObject

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/compass/notification/provider.rb', line 49

def label
  raise NotImplementedError, "#{self.class} must implement #label"
end

#retrieve_notificationsObject

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/compass/notification/provider.rb', line 41

def retrieve_notifications
  raise NotImplementedError, "#{self.class} must implement #retrieve_notifications"
end

#updated_atObject

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/compass/notification/provider.rb', line 53

def updated_at
  raise NotImplementedError, "#{self.class} must implement #updated_at"
end