global_alerts 0.0.1 → 0.2.0

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: 13ab29a8c779ca9887a3a7d5b6d2ad724682632abde1e4a6502c1aacddedd6d2
4
- data.tar.gz: acfb18ef1442f1ee6d4501cd5413f81fef1d414b3b0488446606d2ac5494c927
3
+ metadata.gz: fd3f4670516b8090e20518f954892fba639683e2cb1c1dc77112c67417a82a7a
4
+ data.tar.gz: 221cf06217609ff081d19501a03b58b88e7abfb189aa33f22db9bfc6efe236fb
5
5
  SHA512:
6
- metadata.gz: e6e79f72484f60eb1cd7204c9c88d446eb0045906f65cfbd73cca0cb70d5421bff1001b16c3e6aae4905843bbeb45d15ed6020375a1459932cafd594783ac0e6
7
- data.tar.gz: ce1b3c97ed7fd4e5009e338b2b54fa23d51ad50b99436e96a978493efc0d638946d03b798e40b85578c2c11e270f5750b4b7bc8267df8c37070b78a367476a44
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
- How to use my plugin.
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
- # HTTP.follow.get(GlobalAlerts::Engine.config.url).body.to_s
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
- data&.each do |yaml|
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 == 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
@@ -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.json'
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.module_parent_name.underscore
10
+ config.application_name ||= app.class.parent_name.underscore
11
11
  end
12
12
  end
13
13
  end
@@ -1,3 +1,3 @@
1
1
  module GlobalAlerts
2
- VERSION = '0.0.1'
2
+ VERSION = '0.2.0'
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.1
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-08-24 00:00:00.000000000 Z
11
+ date: 2020-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails