power-compass 0.2.0 → 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: b15f1bb40f641eed660ace8d322edb371b31ee668e0c9fe486c178c9db3d6e5a
4
- data.tar.gz: f9608627370f1fcb144ca1b8f838181d56c79a45a2d397567ad03fe4151d650d
3
+ metadata.gz: b310dc5041bdff68ef213139f0d1c1a05059382b47430f31e9b6024b9e7d6720
4
+ data.tar.gz: a2e420b773128a5027bf199e5c6384b17ff6fec9bcbaf6ba9ff3427cb35eb9e7
5
5
  SHA512:
6
- metadata.gz: 2143a84d1477e820fde55859d54fee4ad5cefaf32a9c1c814e5009917110b0f52b510d08346e811aa9027fe2b3ad56929e55c1ad72847f44d5f84edd85dbf1ae
7
- data.tar.gz: e94d5bbf3feca613d192eb39b205d90e576651cc768043fc3a8b406e3bb46cd9497ae54605a61e89b8a3c0259f0ca8aa405ed951ed2a60f9e1291a1e84c87e45
6
+ metadata.gz: b570ab5a2fa7d4da1bf51cac5e2fcaa5e08396dd89a0cb070a6480cca24c4cebbb2f59cc42d3946ab81fbdc554945d1ed9f08574f662e146df5c0127f23c55b1
7
+ data.tar.gz: 7239db58aeb179be84317182ba7db0359744d52775eb12cc2ff31460400d02a6b96922dbaa5d0fef1fdb0ae2912a8a6111e6c3b4dbb7f91f2ba2ac4cbe2a4f9c
@@ -33,5 +33,13 @@ module Compass
33
33
  def validate_context_id
34
34
  current_context_id.to_s.eql?(params[:context_id])
35
35
  end
36
+
37
+ def set_cache_headers(config)
38
+ if config
39
+ expires_in(*Array(config))
40
+ else
41
+ expires_now
42
+ end
43
+ end
36
44
  end
37
45
  end
@@ -7,7 +7,7 @@ module Compass
7
7
  etag { menu_items.maximum(:updated_at) }
8
8
 
9
9
  def index
10
- expires_in(*Array(Compass.config.menu.cache))
10
+ set_cache_headers(Compass.config.menu.cache)
11
11
 
12
12
  return unless stale? menu_items, etag: "compass-menu"
13
13
 
@@ -2,14 +2,20 @@ require "compass/notification/provider"
2
2
 
3
3
  module Compass
4
4
  class NotificationController < ApplicationController
5
- def index
6
- expires_in(*Array(Compass.config.notification.cache), public: true)
5
+ etag { providers.map(&:hash) }
7
6
 
8
- providers = Compass::Notification::Provider.global_notifications(current_context)
7
+ def index
8
+ set_cache_headers(Compass.config.notification.cache)
9
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.0"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power-compass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Palhares
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-10-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubygems_version: 3.6.2
91
+ rubygems_version: 3.6.9
92
92
  specification_version: 4
93
93
  summary: Compass provides backend services for Compass:UI
94
94
  test_files: []