global_alerts 0.0.1 → 0.2.0
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 +4 -4
- data/README.md +21 -1
- data/app/models/global_alerts/alert.rb +16 -5
- data/lib/global_alerts/engine.rb +2 -2
- data/lib/global_alerts/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd3f4670516b8090e20518f954892fba639683e2cb1c1dc77112c67417a82a7a
|
4
|
+
data.tar.gz: 221cf06217609ff081d19501a03b58b88e7abfb189aa33f22db9bfc6efe236fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5913609eb9b54f302d751c9bf04017e1f39d72e89a367e9a8fef361d2f0cff49a50fed916af0ef630a2110f7f0a219b11d767faa7425b3d9c065a25f118ac9c
|
7
|
+
data.tar.gz: 91a55525d7d1281bcfba1c73f9d669a68029c92ecc01adaa5ff000de48b538adb63e41b1149938f279a84e70bd8d7d49267e6fef7a355df22ed6341bd5079ec6
|
data/README.md
CHANGED
@@ -2,7 +2,27 @@
|
|
2
2
|
Short description and motivation.
|
3
3
|
|
4
4
|
## Usage
|
5
|
-
|
5
|
+
|
6
|
+
### Consuming
|
7
|
+
|
8
|
+
- Add the gem
|
9
|
+
- Set any engine configuration:
|
10
|
+
- GlobalAlerts::Engine.config.cache (Cache for the alerts feed; defaults to the Rails cache)
|
11
|
+
- GlobalAlerts::Engine.config.application_name (Used for app-specific alerts, default is derived from the application name)
|
12
|
+
- GlobalAlerts::Engine.config.url (URL to pull alerts from)
|
13
|
+
- Render the global_alerts/alerts partial
|
14
|
+
|
15
|
+
### Publishing alerts
|
16
|
+
|
17
|
+
In a YAML file (e.g. https://github.com/sul-dlss/global_alerts/blob/main/sul.yaml by default), configure alerts using:
|
18
|
+
|
19
|
+
- `html`: the HTML-safe alert text
|
20
|
+
- `application_name`: used for application-specific alert text; matches against the consumer's `GlobalAlerts::Engine.config.application_name`
|
21
|
+
- `from`/`to`: schedule alerts for particular times (also supports open-ended ranges with only `from` or only `to`)
|
22
|
+
|
23
|
+
Consuming applications will pick only the first relevant alert.
|
24
|
+
|
25
|
+
Restart any consuming applications.
|
6
26
|
|
7
27
|
## Installation
|
8
28
|
Add this line to your application's Gemfile:
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'http'
|
2
|
+
|
1
3
|
module GlobalAlerts
|
2
4
|
class Alert
|
3
5
|
include ActiveModel::Model
|
@@ -8,12 +10,12 @@ module GlobalAlerts
|
|
8
10
|
return to_enum(:all) unless block_given?
|
9
11
|
|
10
12
|
body = cache.fetch(CACHE_KEY) do
|
11
|
-
|
12
|
-
File.read(GlobalAlerts::Engine.root + 'sul.yaml')
|
13
|
+
HTTP.follow.get(GlobalAlerts::Engine.config.url).body.to_s
|
13
14
|
end
|
14
15
|
|
15
16
|
data = YAML.safe_load(body)
|
16
|
-
|
17
|
+
|
18
|
+
data.dig('alerts')&.each do |yaml|
|
17
19
|
yield new(yaml)
|
18
20
|
end
|
19
21
|
rescue => e
|
@@ -44,10 +46,19 @@ module GlobalAlerts
|
|
44
46
|
delegate :present?, to: :html
|
45
47
|
|
46
48
|
def active?(time: Time.zone.now, for_application: nil)
|
47
|
-
return false if for_application
|
49
|
+
return false if for_application != application_name
|
48
50
|
|
49
51
|
return true if from.nil? && to.nil?
|
50
|
-
|
52
|
+
|
53
|
+
range.cover?(time)
|
54
|
+
end
|
55
|
+
|
56
|
+
def range
|
57
|
+
start_of_range = from.presence && Time.zone.parse(from)
|
58
|
+
start_of_range ||= Time.at(0) unless RUBY_VERSION > '2.7'
|
59
|
+
|
60
|
+
end_of_range = to.presence && Time.zone.parse(to)
|
61
|
+
start_of_range...end_of_range
|
51
62
|
end
|
52
63
|
|
53
64
|
def as_html
|
data/lib/global_alerts/engine.rb
CHANGED
@@ -4,10 +4,10 @@ module GlobalAlerts
|
|
4
4
|
|
5
5
|
config.cache = nil #defaults to Rails.cache
|
6
6
|
config.application_name = nil
|
7
|
-
config.url = 'https://github.com/sul-dlss/global-alerts/raw/main/sul.
|
7
|
+
config.url = 'https://github.com/sul-dlss/global-alerts/raw/main/sul.yaml'
|
8
8
|
|
9
9
|
initializer('global_alerts_default') do |app|
|
10
|
-
config.application_name ||= app.class.
|
10
|
+
config.application_name ||= app.class.parent_name.underscore
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: global_alerts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|