power-compass 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b310dc5041bdff68ef213139f0d1c1a05059382b47430f31e9b6024b9e7d6720
|
|
4
|
+
data.tar.gz: a2e420b773128a5027bf199e5c6384b17ff6fec9bcbaf6ba9ff3427cb35eb9e7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b570ab5a2fa7d4da1bf51cac5e2fcaa5e08396dd89a0cb070a6480cca24c4cebbb2f59cc42d3946ab81fbdc554945d1ed9f08574f662e146df5c0127f23c55b1
|
|
7
|
+
data.tar.gz: 7239db58aeb179be84317182ba7db0359744d52775eb12cc2ff31460400d02a6b96922dbaa5d0fef1fdb0ae2912a8a6111e6c3b4dbb7f91f2ba2ac4cbe2a4f9c
|
|
@@ -2,14 +2,20 @@ require "compass/notification/provider"
|
|
|
2
2
|
|
|
3
3
|
module Compass
|
|
4
4
|
class NotificationController < ApplicationController
|
|
5
|
+
etag { providers.map(&:hash) }
|
|
6
|
+
|
|
5
7
|
def index
|
|
6
8
|
set_cache_headers(Compass.config.notification.cache)
|
|
7
9
|
|
|
8
|
-
providers = Compass::Notification::Provider.global_notifications(current_context)
|
|
9
|
-
|
|
10
10
|
return unless stale?(providers, etag: "compass-notification")
|
|
11
11
|
|
|
12
12
|
render json: providers
|
|
13
13
|
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def providers
|
|
18
|
+
@providers ||= Compass::Notification::Provider.global_notifications(current_context)
|
|
19
|
+
end
|
|
14
20
|
end
|
|
15
21
|
end
|
|
@@ -31,6 +31,10 @@ module Compass
|
|
|
31
31
|
context.each { |key, value| define_singleton_method(key) { value } }
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
def hash
|
|
35
|
+
notifications.pluck(:id).hash
|
|
36
|
+
end
|
|
37
|
+
|
|
34
38
|
def fetch_notifications
|
|
35
39
|
retrieve_notifications
|
|
36
40
|
rescue => e
|
|
@@ -43,7 +47,7 @@ module Compass
|
|
|
43
47
|
end
|
|
44
48
|
|
|
45
49
|
def format_notification(notification)
|
|
46
|
-
raise NotImplementedError, "#{self.class} must implement #format_notification"
|
|
50
|
+
raise NotImplementedError, "#{self.class} must implement #format_notification and return a hash with :id, :title, :body, and :url keys"
|
|
47
51
|
end
|
|
48
52
|
|
|
49
53
|
def label
|
|
@@ -57,11 +61,18 @@ module Compass
|
|
|
57
61
|
def as_json(options = {})
|
|
58
62
|
{
|
|
59
63
|
label: label,
|
|
60
|
-
notifications:
|
|
64
|
+
notifications: notifications
|
|
61
65
|
}
|
|
62
66
|
end
|
|
63
67
|
|
|
64
|
-
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def notifications
|
|
71
|
+
@notifications ||= Array(fetch_notifications).map do |notification|
|
|
72
|
+
formatted = format_notification(notification)
|
|
73
|
+
formatted[:id] ? formatted : raise(ArgumentError, "#{self.class}#format_notification must include :id. Got: #{formatted.inspect}")
|
|
74
|
+
end.compact
|
|
75
|
+
end
|
|
65
76
|
|
|
66
77
|
def log_error(error)
|
|
67
78
|
Compass.logger&.error(
|
data/lib/compass/version.rb
CHANGED