Class: Compass::Notification::Provider

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

Instance Method Summary collapse

Methods included from MustImplement

#must_implement

Constructor Details

#initialize(**context) ⇒ Provider

Returns a new instance of Provider.



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

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

Instance Method Details

#as_json(options = {}) ⇒ Object



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

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

#fetchObject



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

def fetch = must_implement(:fetch)

#hashObject



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

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

#labelObject



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

def label = must_implement(:label)

#notificationsObject



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

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

#updated_atObject



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

def updated_at = must_implement(:updated_at)