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: 00b3955c4f359a7370e04976dc68f405189c9493e411f4ed021f7cc5720831ed
4
- data.tar.gz: 88f25c58a0461d2977a0dd9307f7004b6d88faf796b74673c2fa2badb586a4cd
3
+ metadata.gz: b310dc5041bdff68ef213139f0d1c1a05059382b47430f31e9b6024b9e7d6720
4
+ data.tar.gz: a2e420b773128a5027bf199e5c6384b17ff6fec9bcbaf6ba9ff3427cb35eb9e7
5
5
  SHA512:
6
- metadata.gz: e059eed884c947fd7ad6ec20a1d5943c603eee8abe3b6b7c1aff04bc8a721e9475248950a3ccec01122b1a8d6df27cc1ec4ea25a105b48751894c5cbea87e7c8
7
- data.tar.gz: 273b8db4505662c7d6ebfed38c67524ef2ff7e867ff84dde95b2eda65523884a39b49e1aad6ce97254089fef0dacbfa875a54d23df32c5ce17bb54c383a866f0
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: Array(fetch_notifications).map { |notification| format_notification(notification) }.compact
64
+ notifications: notifications
61
65
  }
62
66
  end
63
67
 
64
- private
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(
@@ -1,3 +1,3 @@
1
1
  module Compass
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power-compass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Palhares