Class: Compass::Notification::Provider
- Inherits:
-
Object
- Object
- Compass::Notification::Provider
- Includes:
- JsonFormatter
- Defined in:
- lib/compass/notification/provider.rb
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #fetch ⇒ Object
- #hash ⇒ Object
-
#initialize(**context) ⇒ Provider
constructor
A new instance of Provider.
- #label ⇒ Object
- #notifications ⇒ Object
- #updated_at ⇒ Object
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( = {}) { label: label, notifications: notifications }.compact.as_json() end |
#fetch ⇒ Object
24 |
# File 'lib/compass/notification/provider.rb', line 24 def fetch = must_implement(:fetch) |
#hash ⇒ Object
13 14 15 |
# File 'lib/compass/notification/provider.rb', line 13 def hash notifications.pluck(:id).hash end |
#label ⇒ Object
26 |
# File 'lib/compass/notification/provider.rb', line 26 def label = must_implement(:label) |
#notifications ⇒ Object
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_at ⇒ Object
28 |
# File 'lib/compass/notification/provider.rb', line 28 def updated_at = must_implement(:updated_at) |