global_alerts 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 13ab29a8c779ca9887a3a7d5b6d2ad724682632abde1e4a6502c1aacddedd6d2
4
+ data.tar.gz: acfb18ef1442f1ee6d4501cd5413f81fef1d414b3b0488446606d2ac5494c927
5
+ SHA512:
6
+ metadata.gz: e6e79f72484f60eb1cd7204c9c88d446eb0045906f65cfbd73cca0cb70d5421bff1001b16c3e6aae4905843bbeb45d15ed6020375a1459932cafd594783ac0e6
7
+ data.tar.gz: ce1b3c97ed7fd4e5009e338b2b54fa23d51ad50b99436e96a978493efc0d638946d03b798e40b85578c2c11e270f5750b4b7bc8267df8c37070b78a367476a44
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2020 The Board of Trustees of the Leland Stanford Junior University.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,25 @@
1
+ # GlobalAlerts
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'global_alerts'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install global_alerts
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'GlobalAlerts'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/global_alerts .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ module GlobalAlerts
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module GlobalAlerts
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module GlobalAlerts
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module GlobalAlerts
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,57 @@
1
+ module GlobalAlerts
2
+ class Alert
3
+ include ActiveModel::Model
4
+
5
+ CACHE_KEY = 'global-alerts'
6
+
7
+ def self.all
8
+ return to_enum(:all) unless block_given?
9
+
10
+ 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
+ end
14
+
15
+ data = YAML.safe_load(body)
16
+ data&.each do |yaml|
17
+ yield new(yaml)
18
+ end
19
+ rescue => e
20
+ Rails.logger.warn(e)
21
+ raise(e) if Rails.env.development?
22
+
23
+ []
24
+ end
25
+
26
+ def self.active(time = Time.zone.now)
27
+ active_alert = all.find do |alert|
28
+ alert.active?(time: time, for_application: GlobalAlerts::Engine.config.application_name)
29
+ end
30
+
31
+ active_alert ||= all.find do |alert|
32
+ alert.active?(time: time)
33
+ end
34
+
35
+ active_alert
36
+ end
37
+
38
+ def self.cache
39
+ GlobalAlerts::Engine.config.cache || Rails.cache
40
+ end
41
+
42
+ attr_accessor :html, :from, :to, :application_name
43
+
44
+ delegate :present?, to: :html
45
+
46
+ def active?(time: Time.zone.now, for_application: nil)
47
+ return false if for_application == application_name
48
+
49
+ return true if from.nil? && to.nil?
50
+ ((from.presence && Time.zone.parse(from))...(to.presence && Time.zone.parse(to))).cover?(time)
51
+ end
52
+
53
+ def as_html
54
+ html.html_safe
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,5 @@
1
+ module GlobalAlerts
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ <% alert = GlobalAlerts::Alert.active %>
2
+
3
+ <% if alert.present? %>
4
+ <div class="global-alert">
5
+ <%= alert.as_html %>
6
+ </div>
7
+ <% end %>
@@ -0,0 +1 @@
1
+ GlobalAlerts::Alert.cache.delete(GlobalAlerts::Alert::CACHE_KEY)
@@ -0,0 +1,2 @@
1
+ GlobalAlerts::Engine.routes.draw do
2
+ end
@@ -0,0 +1,5 @@
1
+ require "global_alerts/engine"
2
+
3
+ module GlobalAlerts
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,13 @@
1
+ module GlobalAlerts
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace GlobalAlerts
4
+
5
+ config.cache = nil #defaults to Rails.cache
6
+ config.application_name = nil
7
+ config.url = 'https://github.com/sul-dlss/global-alerts/raw/main/sul.json'
8
+
9
+ initializer('global_alerts_default') do |app|
10
+ config.application_name ||= app.class.module_parent_name.underscore
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module GlobalAlerts
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :global_alerts do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: global_alerts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Beer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '5.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
33
+ - !ruby/object:Gem::Dependency
34
+ name: http
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: sqlite3
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ description:
62
+ email:
63
+ - cabeer@stanford.edu
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - app/assets/config/global_alerts_manifest.js
72
+ - app/assets/stylesheets/global_alerts/application.css
73
+ - app/controllers/global_alerts/application_controller.rb
74
+ - app/helpers/global_alerts/application_helper.rb
75
+ - app/jobs/global_alerts/application_job.rb
76
+ - app/mailers/global_alerts/application_mailer.rb
77
+ - app/models/global_alerts/alert.rb
78
+ - app/models/global_alerts/application_record.rb
79
+ - app/views/global_alerts/_alerts.html.erb
80
+ - config/initializers/global_alerts_initializer.rb
81
+ - config/routes.rb
82
+ - lib/global_alerts.rb
83
+ - lib/global_alerts/engine.rb
84
+ - lib/global_alerts/version.rb
85
+ - lib/tasks/global_alerts_tasks.rake
86
+ homepage: https://github.com/sul-dlss/global_alerts
87
+ licenses:
88
+ - Apache 2.0
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubygems_version: 3.1.2
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: SUL global alerts as a service
109
+ test_files: []