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



61
62
63
64
65
66
# File 'lib/compass/notification/provider.rb', line 61

def as_json(options = {})
  {
    label: label,
    notifications: notifications
  }
end

#fetch_notificationsObject



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

def fetch_notifications
  retrieve_notifications
rescue => e
  log_error(e)
  []
end

#format_notification(notification) ⇒ Object

Raises:

  • (NotImplementedError)


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

def format_notification(notification)
  raise NotImplementedError, "#{self.class} must implement #format_notification and return a hash with :id, :title, :body, and :url keys"
end

#hashObject



34
35
36
# File 'lib/compass/notification/provider.rb', line 34

def hash
  notifications.pluck(:id).hash
end

#labelObject

Raises:

  • (NotImplementedError)


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

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

#retrieve_notificationsObject

Raises:

  • (NotImplementedError)


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

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

#updated_atObject

Raises:

  • (NotImplementedError)


57
58
59
# File 'lib/compass/notification/provider.rb', line 57

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