ddr-alerts 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/db/migrate/20150130204030_drop_message_contexts_table.rb +13 -0
- data/lib/ddr/alerts.rb +0 -1
- data/lib/ddr/alerts/message.rb +1 -7
- data/lib/ddr/alerts/version.rb +1 -1
- data/lib/tasks/ddr_alerts.rake +2 -23
- data/spec/dummy/db/schema.rb +1 -10
- data/spec/factories/message_factories.rb +0 -8
- data/spec/models/message_spec.rb +0 -10
- metadata +3 -5
- data/lib/ddr/alerts/message_context.rb +0 -15
- data/spec/factories/message_context_factories.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b590d7401408eae1859827c6563648c83cf8545
|
4
|
+
data.tar.gz: d8cd1844a137ddb6700a6baa5924685a6f5f3e57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92b64450b0f0ddc7460236975ee19f4d9efa145fc26cc1a3ce8336e7dbce86b2b2b22422583c341ca1b5b73a150ddbffcd2be05ab13c4d5d6078b7d0d68fb1d1
|
7
|
+
data.tar.gz: 6e068337f78316a1ea5909f2f93dad2a3999d559b71b7256f6d2f4e2760088351046138f6414d143abc13c4932838c16a9551d54d291dba391fd9dc47147a271
|
data/README.md
CHANGED
@@ -37,14 +37,14 @@ then
|
|
37
37
|
Ddr::Alerts contains a view partial (ddr/alerts/message/_alert_message.html.erb) that displays the alert messages. This partial depends on
|
38
38
|
the local 'alert_messages' to contain an array of Ddr::Alert::Message which are to be displayed. Render this partial in the desired
|
39
39
|
view / layout of your application, passing in the appropriate value for the 'alert_messages' local. For example, override Blacklight's
|
40
|
-
shared/_flash_messages.html.erb as shown below to include all active alert messages
|
40
|
+
shared/_flash_messages.html.erb as shown below to include all active alert messages above the application's
|
41
41
|
flash messages on each page:
|
42
42
|
|
43
43
|
```
|
44
44
|
<div class="row">
|
45
45
|
<div class="col-md-12">
|
46
46
|
<div id="main-flashes">
|
47
|
-
<%= render partial: '/ddr/alerts/message/alert_message', locals: { alert_messages: Ddr::Alerts::Message.active
|
47
|
+
<%= render partial: '/ddr/alerts/message/alert_message', locals: { alert_messages: Ddr::Alerts::Message.active } %>
|
48
48
|
<%= yield %>
|
49
49
|
</div>
|
50
50
|
</div>
|
data/lib/ddr/alerts.rb
CHANGED
data/lib/ddr/alerts/message.rb
CHANGED
@@ -2,17 +2,11 @@ module Ddr
|
|
2
2
|
module Alerts
|
3
3
|
class Message < ActiveRecord::Base
|
4
4
|
|
5
|
-
has_many :contexts, class_name: "Ddr::Alerts::MessageContext", inverse_of: :message, dependent: :destroy
|
6
|
-
|
7
5
|
scope :active, -> { where(active: true) }
|
8
6
|
|
9
|
-
scope :ddr, -> { joins(:contexts).where(ddr_alerts_message_contexts: { context: Ddr::Alerts::MessageContext::CONTEXT_DDR }) }
|
10
|
-
scope :repository, -> { joins(:contexts).where(ddr_alerts_message_contexts: { context: Ddr::Alerts::MessageContext::CONTEXT_REPOSITORY }) }
|
11
|
-
|
12
7
|
def to_s
|
13
8
|
actv = active ? 'ACTIVE' : 'INACTIVE'
|
14
|
-
|
15
|
-
"[#{id}] [#{ctxs.join(';')}] [#{actv}] [\"#{message}\"]"
|
9
|
+
"[#{id}] [#{actv}] [\"#{message}\"]"
|
16
10
|
end
|
17
11
|
end
|
18
12
|
end
|
data/lib/ddr/alerts/version.rb
CHANGED
data/lib/tasks/ddr_alerts.rake
CHANGED
@@ -3,17 +3,9 @@ namespace :ddr_alerts do
|
|
3
3
|
desc "Create an alert message"
|
4
4
|
task :create => :environment do
|
5
5
|
puts "ERROR: Must specify message text. Ex.: MESSAGE='This is an alert message.'" unless ENV['MESSAGE']
|
6
|
-
|
7
|
-
if ENV['MESSAGE'] && ENV['CONTEXT']
|
6
|
+
if ENV['MESSAGE']
|
8
7
|
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
8
|
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
9
|
if msg.save
|
18
10
|
puts "Created Alert Message"
|
19
11
|
msg.reload
|
@@ -27,20 +19,7 @@ namespace :ddr_alerts do
|
|
27
19
|
desc "List alert messages"
|
28
20
|
task :list => :environment do
|
29
21
|
active = ENV['ACTIVE'] == 'true' ? true : false
|
30
|
-
|
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
|
22
|
+
msgs = active ? Ddr::Alerts::Message.active : Ddr::Alerts::Message.all
|
44
23
|
msgs.each { |msg| puts msg }
|
45
24
|
end
|
46
25
|
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,16 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
15
|
-
|
16
|
-
create_table "ddr_alerts_message_contexts", force: true do |t|
|
17
|
-
t.integer "message_id"
|
18
|
-
t.string "context"
|
19
|
-
t.datetime "created_at"
|
20
|
-
t.datetime "updated_at"
|
21
|
-
end
|
22
|
-
|
23
|
-
add_index "ddr_alerts_message_contexts", ["message_id"], name: "index_ddr_alerts_message_contexts_on_message_id"
|
14
|
+
ActiveRecord::Schema.define(version: 20150130204030) do
|
24
15
|
|
25
16
|
create_table "ddr_alerts_messages", force: true do |t|
|
26
17
|
t.text "message"
|
@@ -10,14 +10,6 @@ FactoryGirl.define do
|
|
10
10
|
active false
|
11
11
|
end
|
12
12
|
|
13
|
-
trait :ddr do
|
14
|
-
contexts { [ FactoryGirl.create(:message_context, :ddr) ] }
|
15
|
-
end
|
16
|
-
|
17
|
-
trait :repository do
|
18
|
-
contexts { [ FactoryGirl.create(:message_context, :repository) ] }
|
19
|
-
end
|
20
|
-
|
21
13
|
end
|
22
14
|
|
23
15
|
end
|
data/spec/models/message_spec.rb
CHANGED
@@ -14,16 +14,6 @@ module Ddr
|
|
14
14
|
expect(Message.active).to_not include(inactive_msg)
|
15
15
|
end
|
16
16
|
end
|
17
|
-
context "contexts" do
|
18
|
-
let(:ddr_msg) { FactoryGirl.create(:message, :ddr) }
|
19
|
-
let(:repository_msg) { FactoryGirl.create(:message, :repository) }
|
20
|
-
it "should return the correct entries" do
|
21
|
-
expect(Message.ddr).to include(ddr_msg)
|
22
|
-
expect(Message.ddr).to_not include(repository_msg)
|
23
|
-
expect(Message.repository).to include(repository_msg)
|
24
|
-
expect(Message.repository).to_not include(ddr_msg)
|
25
|
-
end
|
26
|
-
end
|
27
17
|
end
|
28
18
|
end
|
29
19
|
|
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: 1.0.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:
|
11
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -136,12 +136,12 @@ files:
|
|
136
136
|
- config/routes.rb
|
137
137
|
- db/migrate/20141215160128_create_ddr_alerts_messages.rb
|
138
138
|
- db/migrate/20141215161516_create_ddr_alerts_message_contexts.rb
|
139
|
+
- db/migrate/20150130204030_drop_message_contexts_table.rb
|
139
140
|
- ddr-alerts.gemspec
|
140
141
|
- lib/ddr-alerts.rb
|
141
142
|
- lib/ddr/alerts.rb
|
142
143
|
- lib/ddr/alerts/engine.rb
|
143
144
|
- lib/ddr/alerts/message.rb
|
144
|
-
- lib/ddr/alerts/message_context.rb
|
145
145
|
- lib/ddr/alerts/version.rb
|
146
146
|
- lib/tasks/ddr_alerts.rake
|
147
147
|
- spec/dummy/README.rdoc
|
@@ -185,7 +185,6 @@ files:
|
|
185
185
|
- spec/dummy/public/422.html
|
186
186
|
- spec/dummy/public/500.html
|
187
187
|
- spec/dummy/public/favicon.ico
|
188
|
-
- spec/factories/message_context_factories.rb
|
189
188
|
- spec/factories/message_factories.rb
|
190
189
|
- spec/models/message_spec.rb
|
191
190
|
- spec/spec_helper.rb
|
@@ -256,7 +255,6 @@ test_files:
|
|
256
255
|
- spec/dummy/public/422.html
|
257
256
|
- spec/dummy/public/500.html
|
258
257
|
- spec/dummy/public/favicon.ico
|
259
|
-
- spec/factories/message_context_factories.rb
|
260
258
|
- spec/factories/message_factories.rb
|
261
259
|
- spec/models/message_spec.rb
|
262
260
|
- spec/spec_helper.rb
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Ddr
|
2
|
-
module Alerts
|
3
|
-
class MessageContext < ActiveRecord::Base
|
4
|
-
|
5
|
-
CONTEXT_DDR = 'ddr'.freeze
|
6
|
-
CONTEXT_REPOSITORY = 'repository'.freeze
|
7
|
-
CONTEXTS = Set.new([ CONTEXT_DDR, CONTEXT_REPOSITORY ]).freeze
|
8
|
-
|
9
|
-
validates :context, inclusion: { in: CONTEXTS }
|
10
|
-
|
11
|
-
belongs_to :message, inverse_of: :contexts
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
FactoryGirl.define do
|
2
|
-
|
3
|
-
factory :message_context, class: Ddr::Alerts::MessageContext do
|
4
|
-
|
5
|
-
trait :ddr do
|
6
|
-
context Ddr::Alerts::MessageContext::CONTEXT_DDR
|
7
|
-
end
|
8
|
-
|
9
|
-
trait :repository do
|
10
|
-
context Ddr::Alerts::MessageContext::CONTEXT_REPOSITORY
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|