advisor 0.3.0.pre → 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/Gemfile.lock +1 -1
- data/lib/advisor/advices/call_logger.rb +9 -2
- data/lib/advisor/version.rb +1 -1
- data/spec/advisor/advices/call_logger_spec.rb +42 -5
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07274c88a6cc965df236304e2cadec348a89b609
|
4
|
+
data.tar.gz: 7008dc31d29852a09368e9f3add2e84e1dc6c61a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c3de77e3ba71106ce800367fedf8a49665425b09dc607d243438bd7e3b1e93f1ebd2924f95596567f47d60a5919d327810bcb49527a50d03f0c00de5db9b932
|
7
|
+
data.tar.gz: bddee9a5ae3777933c009f6c8d911ad188142e2132720174a937072151a39e3708e8f2b8680ae620a7dbc60f4c1878163652545a0b9ccb941e170b0d21679dd4
|
data/Gemfile.lock
CHANGED
@@ -5,8 +5,10 @@ module Advisor
|
|
5
5
|
class CallLogger
|
6
6
|
class << self
|
7
7
|
attr_accessor :default_logger
|
8
|
+
attr_accessor :catch_exception
|
8
9
|
end
|
9
10
|
self.default_logger = Logger.new(STDOUT)
|
11
|
+
self.catch_exception = false
|
10
12
|
|
11
13
|
def initialize(object, method, call_args, **opts)
|
12
14
|
@object = object
|
@@ -24,7 +26,7 @@ module Advisor
|
|
24
26
|
def call
|
25
27
|
logger.info(success_message)
|
26
28
|
yield
|
27
|
-
rescue => e
|
29
|
+
rescue exception_class => e
|
28
30
|
logger.warn(failure_message(e))
|
29
31
|
raise
|
30
32
|
end
|
@@ -36,7 +38,8 @@ module Advisor
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def failure_message(ex)
|
39
|
-
|
41
|
+
backtrace = ["\n", ex.to_s] + ex.backtrace
|
42
|
+
call_message('Failed: ', backtrace.join("\n"))
|
40
43
|
end
|
41
44
|
|
42
45
|
def call_message(prefix, suffix = '')
|
@@ -64,6 +67,10 @@ module Advisor
|
|
64
67
|
def id
|
65
68
|
"[id=#{object.id}]" if object.respond_to?(:id)
|
66
69
|
end
|
70
|
+
|
71
|
+
def exception_class
|
72
|
+
CallLogger.catch_exception ? Exception : StandardError
|
73
|
+
end
|
67
74
|
end
|
68
75
|
end
|
69
76
|
end
|
data/lib/advisor/version.rb
CHANGED
@@ -35,24 +35,61 @@ Called: OpenStruct#the_meaning_of_life(\"the universe\", \"and everything\")"
|
|
35
35
|
call
|
36
36
|
end
|
37
37
|
|
38
|
-
context 'when yielding the block raises an
|
38
|
+
context 'when yielding the block raises an error' do
|
39
39
|
let(:block) { -> () { fail 'deu ruim!' } }
|
40
40
|
|
41
41
|
let(:log_message) do
|
42
|
-
|
43
|
-
Failed: OpenStruct#the_meaning_of_life(\"the universe\", \"and
|
44
|
-
|
42
|
+
/\[Time=#{Time.now}\]\[Thread=#{Thread.current.object_id}\]\
|
43
|
+
\[id=42\]Failed: OpenStruct#the_meaning_of_life\(\"the universe\", \"and\
|
44
|
+
everything\"\).*/
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
let(:error_message) { /deu ruim!/ }
|
48
|
+
|
49
|
+
let(:catch_exception) { false }
|
50
|
+
|
51
|
+
before do
|
52
|
+
allow(logger).to receive(:warn)
|
53
|
+
allow(CallLogger).to receive(:catch_exception)
|
54
|
+
.and_return(catch_exception)
|
55
|
+
end
|
48
56
|
|
49
57
|
it { expect { call }.to raise_error(StandardError, 'deu ruim!') }
|
50
58
|
|
51
59
|
it do
|
52
60
|
expect(logger).to receive(:warn).with(log_message)
|
61
|
+
expect { call }.to raise_error
|
62
|
+
end
|
53
63
|
|
64
|
+
it do
|
65
|
+
expect(logger).to receive(:warn).with(error_message)
|
54
66
|
expect { call }.to raise_error
|
55
67
|
end
|
68
|
+
|
69
|
+
context 'when the error is not a StandardError' do
|
70
|
+
let(:block) { -> { fail Exception, 'deu muito ruim!' } }
|
71
|
+
|
72
|
+
let(:error_message) { /deu muito ruim!/ }
|
73
|
+
|
74
|
+
it do
|
75
|
+
expect(logger).not_to receive(:warn).with(log_message)
|
76
|
+
expect { call }.to raise_error(Exception, 'deu muito ruim!')
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when catching exceptions' do
|
80
|
+
let(:catch_exception) { true }
|
81
|
+
|
82
|
+
it do
|
83
|
+
expect(logger).to receive(:warn).with(log_message)
|
84
|
+
expect { call }.to raise_error(Exception, 'deu muito ruim!')
|
85
|
+
end
|
86
|
+
|
87
|
+
it do
|
88
|
+
expect(logger).to receive(:warn).with(error_message)
|
89
|
+
expect { call }.to raise_error(Exception, 'deu muito ruim!')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
56
93
|
end
|
57
94
|
end
|
58
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: advisor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.0
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Renan Ranelli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: metriks
|
@@ -152,9 +152,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
152
|
version: '2.0'
|
153
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
154
|
requirements:
|
155
|
-
- - "
|
155
|
+
- - ">="
|
156
156
|
- !ruby/object:Gem::Version
|
157
|
-
version:
|
157
|
+
version: '0'
|
158
158
|
requirements: []
|
159
159
|
rubyforge_project:
|
160
160
|
rubygems_version: 2.2.2
|