whoops_notifier 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/whoops_notifier.rb +1 -1
- data/lib/whoops_notifier/investigator.rb +6 -5
- data/lib/whoops_notifier/report.rb +6 -0
- data/lib/whoops_notifier/strategies/basic.rb +1 -1
- data/lib/whoops_notifier/strategy.rb +30 -13
- data/spec/investigator_spec.rb +2 -2
- data/spec/strategy_spec.rb +16 -16
- data/whoops_notifier.gemspec +2 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/whoops_notifier.rb
CHANGED
@@ -14,7 +14,7 @@ module WhoopsNotifier
|
|
14
14
|
|
15
15
|
# @overload notify(evidence)
|
16
16
|
# Notify using the default basic strategy
|
17
|
-
# @param [Hash] evidence the evidence expected by the basic strategy
|
17
|
+
# @param [Hash] evidence the evidence expected by the basic strategy, used by strategy to build report
|
18
18
|
# @overload notify(strategy_name, evidence)
|
19
19
|
# @param [Symbol, String] strategy_name
|
20
20
|
# @param [Hash] evidence same as above
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module WhoopsNotifier
|
2
|
+
|
3
|
+
# A "glue" class which coordinates report creation
|
2
4
|
class Investigator
|
3
5
|
# get data from evidence using a strategy to create a report and decide whether it should be ignored
|
4
|
-
attr_accessor :strategy, :report, :evidence
|
5
|
-
alias :ignore_report? :ignore_report
|
6
|
+
attr_accessor :strategy, :report, :evidence
|
6
7
|
|
7
8
|
def initialize(strategy, evidence)
|
8
9
|
raise ArgumentError, "strategy can not be nil" if strategy.nil?
|
@@ -13,11 +14,11 @@ module WhoopsNotifier
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def investigate!
|
16
|
-
|
17
|
+
strategy.call(report, evidence)
|
17
18
|
end
|
18
19
|
|
19
|
-
def
|
20
|
-
|
20
|
+
def ignore_report?
|
21
|
+
report.ignore?
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -5,6 +5,8 @@ module WhoopsNotifier
|
|
5
5
|
attr_accessor attribute
|
6
6
|
end
|
7
7
|
|
8
|
+
attr_accessor :ignore
|
9
|
+
|
8
10
|
def initialize
|
9
11
|
self.event_time = Time.now
|
10
12
|
end
|
@@ -16,5 +18,9 @@ module WhoopsNotifier
|
|
16
18
|
end
|
17
19
|
h
|
18
20
|
end
|
21
|
+
|
22
|
+
def ignore?
|
23
|
+
ignore
|
24
|
+
end
|
19
25
|
end
|
20
26
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
strategy = WhoopsNotifier::Strategy.new("default::basic")
|
2
2
|
|
3
|
-
strategy.
|
3
|
+
strategy.add_report_builder(:use_basic_hash) do |report, evidence|
|
4
4
|
report.event_type = evidence[:event_type]
|
5
5
|
report.service = evidence[:service]
|
6
6
|
report.environment = evidence[:environment]
|
@@ -1,37 +1,54 @@
|
|
1
1
|
module WhoopsNotifier
|
2
|
+
|
3
|
+
# Strategies are responsible for building Reports and determining whether a
|
4
|
+
# a Report should be ignored.
|
5
|
+
#
|
6
|
+
# Each strategy contains any number of report builders and ignore criteria.
|
7
|
+
#
|
8
|
+
# Each report builder and ignore criteria takes a name. This makes adding a
|
9
|
+
# report builder or ignore criteria more like adding a method - the name
|
10
|
+
# makes it easier to see the intention of the code. It also makes it easier
|
11
|
+
# to get useful info when you inspect the strategy.
|
12
|
+
#
|
13
|
+
# Strategies use call to actually apply modifiers and criteria for the same
|
14
|
+
# reason that Rack uses call. Conceivably, you could add a strategy to the
|
15
|
+
# notifier with
|
16
|
+
# WhoopsNotifier.strategies[:lambda_stragey] = lambda{ |report, evidence|
|
17
|
+
# report.details = evidence[:detail]
|
18
|
+
# }
|
19
|
+
# or something along those lines.
|
2
20
|
class Strategy
|
3
|
-
|
4
|
-
attr_accessor :name, :ignore_criteria, :report_modifiers
|
21
|
+
attr_accessor :name, :ignore_criteria, :report_builders
|
5
22
|
|
6
23
|
def initialize(name)
|
7
24
|
self.name = name
|
8
25
|
self.ignore_criteria = []
|
9
|
-
self.
|
26
|
+
self.report_builders = []
|
10
27
|
WhoopsNotifier.strategies[name] = self
|
11
28
|
end
|
12
29
|
|
13
|
-
def call(
|
14
|
-
|
15
|
-
report_modifier.call(
|
30
|
+
def call(report, evidence)
|
31
|
+
report_builders.each do |report_modifier|
|
32
|
+
report_modifier.call(report, evidence)
|
16
33
|
end
|
17
34
|
|
18
35
|
ignore_criteria.each do |ignore_criterion|
|
19
|
-
if ignore_criterion.call(
|
20
|
-
|
36
|
+
if ignore_criterion.call(report, evidence)
|
37
|
+
report.ignore = true
|
21
38
|
break
|
22
39
|
end
|
23
40
|
end
|
24
41
|
end
|
25
42
|
|
26
|
-
# block should take
|
43
|
+
# block should take two params, the report and the evidence
|
27
44
|
# use evidence to build the report
|
28
|
-
def
|
45
|
+
def add_report_builder(name, &block)
|
29
46
|
give_name(name, block)
|
30
|
-
@
|
47
|
+
@report_builders << block
|
31
48
|
end
|
32
49
|
|
33
50
|
# block takes one param, the investigator's report
|
34
|
-
def
|
51
|
+
def add_ignore_criteria(name, &block)
|
35
52
|
give_name(name, block)
|
36
53
|
@ignore_criteria << block
|
37
54
|
end
|
@@ -44,7 +61,7 @@ module WhoopsNotifier
|
|
44
61
|
end
|
45
62
|
|
46
63
|
def inspect
|
47
|
-
"#{name}\nreport modifiers: #{
|
64
|
+
"#{name}\nreport modifiers: #{report_builders.collect{|r| r.name}.join(", ")}\nignore criteria: #{ignore_criteria.collect{|i| i.name}.join(", ")}"
|
48
65
|
end
|
49
66
|
end
|
50
67
|
end
|
data/spec/investigator_spec.rb
CHANGED
@@ -16,10 +16,10 @@ describe "WhoopsNotifier::Investigator" do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "#investigate!" do
|
19
|
-
it "should not send report if ignore_report is true" do
|
19
|
+
it "should not send report if ignore_report? is true" do
|
20
20
|
strategy = lambda{}
|
21
21
|
investigator = WhoopsNotifier::Investigator.new(strategy, {})
|
22
|
-
investigator.ignore_report
|
22
|
+
investigator.stub(:ignore_report?).and_return(true)
|
23
23
|
|
24
24
|
investigator.should_not_receive(:send_report)
|
25
25
|
|
data/spec/strategy_spec.rb
CHANGED
@@ -7,26 +7,26 @@ describe "WhoopsNotifier::Strategy" do
|
|
7
7
|
WhoopsNotifier.strategies[:test].should == s
|
8
8
|
end
|
9
9
|
|
10
|
-
it "creates empty arrays for ignore criteria and
|
10
|
+
it "creates empty arrays for ignore criteria and report_builders" do
|
11
11
|
s = WhoopsNotifier::Strategy.new(:test)
|
12
12
|
s.ignore_criteria.should == []
|
13
|
-
s.
|
13
|
+
s.report_builders.should == []
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
describe "#
|
17
|
+
describe "#add_report_builder" do
|
18
18
|
it "adds a named block" do
|
19
19
|
s = WhoopsNotifier::Strategy.new(:test)
|
20
|
-
s.
|
20
|
+
s.add_report_builder(:add_message) { |report, evidence| }
|
21
21
|
|
22
|
-
s.
|
22
|
+
s.report_builders.first.name.should == :add_message
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe "#
|
26
|
+
describe "#add_ignore_criteria" do
|
27
27
|
it "adds a named ignore criteria block" do
|
28
28
|
s = WhoopsNotifier::Strategy.new(:test)
|
29
|
-
s.
|
29
|
+
s.add_ignore_criteria(:ignore_if_empty) { |report| }
|
30
30
|
|
31
31
|
s.ignore_criteria.first.name.should == :ignore_if_empty
|
32
32
|
end
|
@@ -37,22 +37,22 @@ describe "WhoopsNotifier::Strategy" do
|
|
37
37
|
strategy = WhoopsNotifier::Strategy.new(:test)
|
38
38
|
investigator = WhoopsNotifier::Investigator.new(strategy, nil)
|
39
39
|
|
40
|
-
strategy.
|
40
|
+
strategy.add_ignore_criteria(:always_ignore) do |report|
|
41
41
|
true
|
42
42
|
end
|
43
43
|
|
44
|
-
strategy.call(investigator)
|
45
|
-
investigator.ignore_report
|
44
|
+
strategy.call(investigator.report, investigator.evidence)
|
45
|
+
investigator.ignore_report?.should == true
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should modify the investigator's report according to the report modifiers" do
|
49
49
|
strategy = WhoopsNotifier::Strategy.new(:test)
|
50
50
|
investigator = WhoopsNotifier::Investigator.new(strategy, {:service => "service"})
|
51
|
-
strategy.
|
51
|
+
strategy.add_report_builder(:add_details){ |report, evidence|
|
52
52
|
report.service = evidence[:service] + " test"
|
53
53
|
}
|
54
54
|
|
55
|
-
strategy.call(investigator)
|
55
|
+
strategy.call(investigator.report, investigator.evidence)
|
56
56
|
|
57
57
|
investigator.report.service.should == "service test"
|
58
58
|
end
|
@@ -63,11 +63,11 @@ describe "WhoopsNotifier::Strategy" do
|
|
63
63
|
strategy = WhoopsNotifier::Strategy.new(:awesome_strategy)
|
64
64
|
investigator = WhoopsNotifier::Investigator.new(strategy, nil)
|
65
65
|
|
66
|
-
strategy.
|
67
|
-
strategy.
|
66
|
+
strategy.add_report_builder(:report1){ }
|
67
|
+
strategy.add_report_builder(:report2){ }
|
68
68
|
|
69
|
-
strategy.
|
70
|
-
strategy.
|
69
|
+
strategy.add_ignore_criteria(:ignore1){ true }
|
70
|
+
strategy.add_ignore_criteria(:ignore2){ true }
|
71
71
|
|
72
72
|
strategy.inspect.should == "awesome_strategy
|
73
73
|
report modifiers: report1, report2
|
data/whoops_notifier.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{whoops_notifier}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Daniel Higginbotham"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-07-09}
|
13
13
|
s.description = %q{Handles basic notification responsibilities and allows creation of report creation strategies}
|
14
14
|
s.email = %q{daniel@flyingmachinestudios.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whoops_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Higginbotham
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-09 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|