ddr-alerts 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/views/ddr/alerts/message/_alert_message.html.erb +1 -1
- data/lib/ddr/alerts/message.rb +5 -0
- data/lib/ddr/alerts/message_context.rb +2 -2
- data/lib/ddr/alerts/version.rb +1 -1
- data/lib/tasks/ddr_alerts.rake +114 -0
- data/spec/views/_alert_message.html.erb_spec.rb +1 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bccb5289094adadc06ce25919db16539b09d98e
|
4
|
+
data.tar.gz: b8f64c0ce75d55fc86b97e24c9aef02bd95b1429
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e52c260a0904c74658b4736a134e9eb7ae9247a51d726106224eaf9255e44f9702a2a4d367a3137795c0523d61097e22457e6b15cb1004b0f04c03821c87a6ca
|
7
|
+
data.tar.gz: 19db82669702d92e0257238c41c394f4e6018d91d8775b06004ebab5de194ad6e1e3090b66beab986b6a539ff488062de615a8edd02d86d089d80b4d641c7057
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<% unless alert_messages.empty? %>
|
2
2
|
<div class="alert alert-danger"><ul class="<%= "list-unstyled" if alert_messages.size == 1 %>">
|
3
3
|
<% alert_messages.each do |msg| %>
|
4
|
-
<li><%= msg.
|
4
|
+
<li><%= msg.html_safe %></li>
|
5
5
|
<% end %>
|
6
6
|
</ul></div>
|
7
7
|
<% end %>
|
data/lib/ddr/alerts/message.rb
CHANGED
@@ -9,6 +9,11 @@ module Ddr
|
|
9
9
|
scope :ddr, -> { joins(:contexts).where(ddr_alerts_message_contexts: { context: Ddr::Alerts::MessageContext::CONTEXT_DDR }) }
|
10
10
|
scope :repository, -> { joins(:contexts).where(ddr_alerts_message_contexts: { context: Ddr::Alerts::MessageContext::CONTEXT_REPOSITORY }) }
|
11
11
|
|
12
|
+
def to_s
|
13
|
+
actv = active ? 'ACTIVE' : 'INACTIVE'
|
14
|
+
ctxs = contexts.map { |context| context.context }
|
15
|
+
"[#{id}] [#{ctxs.join(';')}] [#{actv}] [\"#{message}\"]"
|
16
|
+
end
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
@@ -2,9 +2,9 @@ module Ddr
|
|
2
2
|
module Alerts
|
3
3
|
class MessageContext < ActiveRecord::Base
|
4
4
|
|
5
|
-
CONTEXT_REPOSITORY = 'repository'.freeze
|
6
5
|
CONTEXT_DDR = 'ddr'.freeze
|
7
|
-
|
6
|
+
CONTEXT_REPOSITORY = 'repository'.freeze
|
7
|
+
CONTEXTS = Set.new([ CONTEXT_DDR, CONTEXT_REPOSITORY ]).freeze
|
8
8
|
|
9
9
|
validates :context, inclusion: { in: CONTEXTS }
|
10
10
|
|
data/lib/ddr/alerts/version.rb
CHANGED
@@ -0,0 +1,114 @@
|
|
1
|
+
namespace :ddr_alerts do
|
2
|
+
|
3
|
+
desc "Create an alert message"
|
4
|
+
task :create => :environment do
|
5
|
+
puts "ERROR: Must specify message text. Ex.: MESSAGE='This is an alert message.'" unless ENV['MESSAGE']
|
6
|
+
puts "ERROR: Must specify at least one context. Ex.: CONTEXT=repository" unless ENV['CONTEXT']
|
7
|
+
if ENV['MESSAGE'] && ENV['CONTEXT']
|
8
|
+
active = ENV['ACTIVE'] == 'true' ? true : false
|
9
|
+
contexts = ENV['CONTEXT'].split(';').map(&:strip)
|
10
|
+
contexts.each do |context|
|
11
|
+
raise "Invalid context: #{context}" unless Ddr::Alerts::MessageContext::CONTEXTS.include?(context)
|
12
|
+
end
|
13
|
+
msg = Ddr::Alerts::Message.new(message: ENV['MESSAGE'], active: active)
|
14
|
+
contexts.each do |context|
|
15
|
+
msg.contexts << Ddr::Alerts::MessageContext.new(context: context)
|
16
|
+
end
|
17
|
+
if msg.save
|
18
|
+
puts "Created Alert Message"
|
19
|
+
msg.reload
|
20
|
+
puts msg
|
21
|
+
else
|
22
|
+
puts "ERROR: Unable to create alert message"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "List alert messages"
|
28
|
+
task :list => :environment do
|
29
|
+
active = ENV['ACTIVE'] == 'true' ? true : false
|
30
|
+
if ENV['CONTEXT']
|
31
|
+
contexts = ENV['CONTEXT'].split(';').map(&:strip)
|
32
|
+
contexts.each do |context|
|
33
|
+
raise "Invalid context: #{context}" unless Ddr::Alerts::MessageContext::CONTEXTS.include?(context)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
active_filter_msgs = active ? Ddr::Alerts::Message.active : Ddr::Alerts::Message.all
|
37
|
+
if contexts.blank? || contexts.to_set == Ddr::Alerts::MessageContext::CONTEXTS
|
38
|
+
msgs = active_filter_msgs
|
39
|
+
else
|
40
|
+
context_filter_msgs = []
|
41
|
+
contexts.each { |context| context_filter_msgs << active_filter_msgs.send(context) }
|
42
|
+
msgs = SortedSet.new(context_filter_msgs.flatten)
|
43
|
+
end
|
44
|
+
msgs.each { |msg| puts msg }
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Activate an alert message"
|
48
|
+
task :activate => :environment do
|
49
|
+
puts "ERROR: Must specify message ID. Ex.: MESSAGE_ID=4" unless ENV['MESSAGE_ID']
|
50
|
+
if ENV['MESSAGE_ID']
|
51
|
+
begin
|
52
|
+
msg = Ddr::Alerts::Message.find(ENV['MESSAGE_ID'].to_i)
|
53
|
+
if msg.active
|
54
|
+
puts "WARNING: Message is already active"
|
55
|
+
else
|
56
|
+
msg.active = true
|
57
|
+
if msg.save
|
58
|
+
puts "Message activated"
|
59
|
+
else
|
60
|
+
puts "ERROR: Unable to activate message"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
msg.reload
|
64
|
+
puts msg
|
65
|
+
rescue ActiveRecord::RecordNotFound => e
|
66
|
+
puts "ERROR: #{e.message}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "De-activate an alert message"
|
72
|
+
task :deactivate => :environment do
|
73
|
+
puts "ERROR: Must specify message ID. Ex.: MESSAGE_ID=4" unless ENV['MESSAGE_ID']
|
74
|
+
if ENV['MESSAGE_ID']
|
75
|
+
begin
|
76
|
+
msg = Ddr::Alerts::Message.find(ENV['MESSAGE_ID'].to_i)
|
77
|
+
if !msg.active
|
78
|
+
puts "WARNING: Message is not currently active"
|
79
|
+
else
|
80
|
+
msg.active = false
|
81
|
+
if msg.save
|
82
|
+
puts "Message deactivated"
|
83
|
+
else
|
84
|
+
puts "ERROR: Unable to deactivate message"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
msg.reload
|
88
|
+
puts msg
|
89
|
+
rescue ActiveRecord::RecordNotFound => e
|
90
|
+
puts "ERROR: #{e.message}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
desc "Delete an alert message"
|
96
|
+
task :delete => :environment do
|
97
|
+
puts "ERROR: Must specify message ID. Ex.: MESSAGE_ID=4" unless ENV['MESSAGE_ID']
|
98
|
+
if ENV['MESSAGE_ID']
|
99
|
+
begin
|
100
|
+
msg = Ddr::Alerts::Message.find(ENV['MESSAGE_ID'].to_i)
|
101
|
+
msg.destroy
|
102
|
+
if msg.destroyed?
|
103
|
+
puts "Message deleted"
|
104
|
+
puts msg
|
105
|
+
else
|
106
|
+
puts "ERROR: Unable to delete message"
|
107
|
+
end
|
108
|
+
rescue ActiveRecord::RecordNotFound => e
|
109
|
+
puts "ERROR: #{e.message}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
@@ -2,8 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe 'ddr/alerts/message/_alert_message.html.erb', type: :view do
|
4
4
|
|
5
|
-
|
6
|
-
before { allow(view).to receive(:alert_messages).and_return(msgs) }
|
5
|
+
before { allow(view).to receive(:alert_messages).and_return([ "AAA", "BBB" ]) }
|
7
6
|
it "displays the messages" do
|
8
7
|
render partial: 'ddr/alerts/message/alert_message.html.erb'
|
9
8
|
expect(rendered).to match(/AAA/)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddr-alerts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Coble
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- lib/ddr/alerts/message.rb
|
144
144
|
- lib/ddr/alerts/message_context.rb
|
145
145
|
- lib/ddr/alerts/version.rb
|
146
|
+
- lib/tasks/ddr_alerts.rake
|
146
147
|
- spec/dummy/README.rdoc
|
147
148
|
- spec/dummy/Rakefile
|
148
149
|
- spec/dummy/app/assets/images/.keep
|