global_alerts 0.0.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0eda069f5366b4292b3dbd6e3f50c665c811d8ef47209234e8b0b65229e31e96
4
- data.tar.gz: 860d1119003a9f9e1e85ec62c01b4df409f4ffed6b6a9368636b12523486d420
3
+ metadata.gz: 2b13e756e2ad666be24edad46f98b48a98b0c82f697b75d0fe8db10d0af23797
4
+ data.tar.gz: ccdb8b3f5421e602d91789418b657d89bd39b36317c863e7cf25853a49d4bdc3
5
5
  SHA512:
6
- metadata.gz: 890d04169c6c938cd7d36e62a62cf46843f6aa15cc15e0f4cd559f6a6ed6d829b4ca1e4e4ae566e89ab6eff813132580029d00581a2b413af401b0e68416bfd6
7
- data.tar.gz: 658cdbb2effb5d683a72adad53b4dc32de46f99035d3514f46f607e90ebac2f2d1eb386f229a3bf92050df7e0ee5eebb1ac7ffb8a9fc0efa9da811fd3a07750a
6
+ metadata.gz: 64d67a541cbd5fee1530f559ca153cda4dc39e00cbd48aeb82516b1cb312b775c26a9e313004bb76a475ead53da3be49774dfbaf7a90419a62a433e6fa4afc6d
7
+ data.tar.gz: bff01e26847463982b0e2b07b18a94073ba04f5e4fb4ff8cf0750f02209d86d82abed7bcbf5562b4d0a6c6df0b7de073acf2df890b72fb51e64040b122c4c751
data/README.md CHANGED
@@ -1,8 +1,68 @@
1
1
  # GlobalAlerts
2
- Short description and motivation.
2
+ A gem for managing user-facing alerts across the portfolio.
3
+ ⚠️[See current alerts](https://github.com/sul-dlss/global_alerts/blob/main/sul.yaml)
3
4
 
4
5
  ## Usage
5
- How to use my plugin.
6
+
7
+ ### Consuming
8
+
9
+ - Add the gem
10
+ - Set GLOBAL_ALERTS to `<%= true %>` in the application settings.
11
+ - Set any engine configuration in the consuming application's initializers:
12
+ - GlobalAlerts::Engine.config.cache (Cache for the alerts feed; defaults to the Rails cache)
13
+ - GlobalAlerts::Engine.config.application_name (Used for app-specific alerts, default is derived from the application name)
14
+ - GlobalAlerts::Engine.config.url (URL to pull alerts from)
15
+ - Render the global_alerts/alerts partial
16
+
17
+ ### Publishing alerts
18
+
19
+ In a YAML file (e.g. https://github.com/sul-dlss/global_alerts/blob/main/sul.yaml by default), configure alerts using:
20
+
21
+ - `html`: the HTML-safe alert text
22
+ - `application_name`: used for application-specific alert text; matches against the consumer's `GlobalAlerts::Engine.config.application_name`
23
+ - `from`/`to`: schedule alerts for particular times (also supports open-ended ranges with only `from` or only `to`)
24
+
25
+ Consuming applications will pick only the first relevant alert.
26
+
27
+ Restart any consuming applications.
28
+
29
+ ### Example Alerts
30
+
31
+ #### Basic alert
32
+ ```
33
+ alerts:
34
+ - html: A single <em>sample alert</em> across all apps. This will appear until manually removed from the YML file.
35
+ ```
36
+
37
+ #### `to`
38
+ ```
39
+ alerts:
40
+ - to: '2020-12-07T12:00:00-07:00'
41
+ html: This message will appear immediately and will expire on December 7th at noon.
42
+ ```
43
+
44
+ #### `from`
45
+ ```
46
+ alerts:
47
+ - from: '2020-12-07T12:00:00-07:00'
48
+ html: This message will begin on December 7th at noon and must be manually removed.
49
+ ```
50
+ #### `from` and `to`
51
+ ```
52
+ alerts:
53
+ - from: '2020-12-24T12:00:00-07:00'
54
+ to: '2020-12-25T12:00:00-07:00'
55
+ html: This message will appear from December 24th at noon and expire on December 25th at noon. This YML should be removed later.
56
+ ```
57
+
58
+ #### `application_name`
59
+ ```
60
+ alerts:
61
+ - application_name: 'MyLibrary
62
+ html: This message will appear on MyLibrary until manually removed.
63
+ - html: This alert will appear on all other applications with GLOBAL_ALERTS enabled
64
+ ```
65
+
6
66
 
7
67
  ## Installation
8
68
  Add this line to your application's Gemfile:
@@ -20,6 +80,3 @@ Or install it yourself as:
20
80
  ```bash
21
81
  $ gem install global_alerts
22
82
  ```
23
-
24
- ## Contributing
25
- Contribution directions go here.
@@ -1,3 +1,5 @@
1
+ require 'http'
2
+
1
3
  module GlobalAlerts
2
4
  class Alert
3
5
  include ActiveModel::Model
@@ -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 == application_name
49
+ return false if for_application != application_name
48
50
 
49
51
  return true if from.nil? && to.nil?
50
- ((from.presence && Time.zone.parse(from))...(to.presence && Time.zone.parse(to))).cover?(time)
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
@@ -1 +1,3 @@
1
- GlobalAlerts::Alert.cache.delete(GlobalAlerts::Alert::CACHE_KEY)
1
+ Rails.application.reloader.to_prepare do
2
+ GlobalAlerts::Alert.cache.delete(GlobalAlerts::Alert::CACHE_KEY)
3
+ end
@@ -7,7 +7,8 @@ module GlobalAlerts
7
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.parent_name.underscore
10
+ # parent_name is deprecated in Rails 6.1
11
+ config.application_name ||= app.class.respond_to?(:parent_name) ? app.class.parent_name.underscore : app.class.module_parent_name.underscore
11
12
  end
12
13
  end
13
14
  end
@@ -1,3 +1,3 @@
1
1
  module GlobalAlerts
2
- VERSION = '0.0.3'
2
+ VERSION = '0.3.1'
3
3
  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.3
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-24 00:00:00.000000000 Z
11
+ date: 2021-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -58,7 +58,7 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
- description:
61
+ description:
62
62
  email:
63
63
  - cabeer@stanford.edu
64
64
  executables: []
@@ -87,7 +87,7 @@ homepage: https://github.com/sul-dlss/global_alerts
87
87
  licenses:
88
88
  - Apache 2.0
89
89
  metadata: {}
90
- post_install_message:
90
+ post_install_message:
91
91
  rdoc_options: []
92
92
  require_paths:
93
93
  - lib
@@ -102,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubygems_version: 3.1.2
106
- signing_key:
105
+ rubygems_version: 3.2.3
106
+ signing_key:
107
107
  specification_version: 4
108
108
  summary: SUL global alerts as a service
109
109
  test_files: []