Class: Compass::Notification::Provider

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

Instance Method Summary collapse

Constructor Details

#initialize(**context) ⇒ Provider

Returns a new instance of Provider.



8
9
10
11
# File 'lib/compass/notification/provider.rb', line 8

def initialize(**context)
  @context = context
  context.each { |key, value| define_singleton_method(key) { value } }
end

Instance Method Details

#as_json(options = {}) ⇒ Object



30
31
32
33
34
35
# File 'lib/compass/notification/provider.rb', line 30

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

#fetchObject



24
# File 'lib/compass/notification/provider.rb', line 24

def fetch = must_implement(:fetch)

#hashObject



13
14
15
# File 'lib/compass/notification/provider.rb', line 13

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

#labelObject



26
# File 'lib/compass/notification/provider.rb', line 26

def label = must_implement(:label)

#notificationsObject



17
18
19
20
21
22
# File 'lib/compass/notification/provider.rb', line 17

def notifications
  @notifications ||= Array(fetch).map { |notification| format(notification) }
rescue => e
  log_error(e)
  []
end

#updated_atObject



28
# File 'lib/compass/notification/provider.rb', line 28

def updated_at = must_implement(:updated_at)