advisor 0.5.0 → 0.5.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/advisor/advices/call_logger.rb +7 -4
- data/lib/advisor/version.rb +1 -1
- data/spec/advisor/advices/call_logger_spec.rb +7 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bd705ca8a6e531d27ba1f7477118d039fd8e93e
|
4
|
+
data.tar.gz: f0372ed273abef5b744b0509c35d25887220081b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d662f5d5c8270323bd8023c3f9f27b13fbe2fc7b6b0081a37d2975cf743d889b71336f2f61cc9859a7630ed489bbdfbd9f1db87711b5d6b9ef4b72dc354364f9
|
7
|
+
data.tar.gz: 8d38aa47bcdad42014e600e9492dcde1c1c789f76c15fd357d793e10216f740a0935534d245bbdccfb397dbac5b54c04f6ecfca57a9dc7550f7545de8a64f828
|
data/Gemfile.lock
CHANGED
@@ -4,21 +4,23 @@ module Advisor
|
|
4
4
|
module Advices
|
5
5
|
class CallLogger
|
6
6
|
class << self
|
7
|
+
attr_accessor :backtrace_cleaner
|
7
8
|
attr_accessor :default_logger
|
8
9
|
attr_accessor :catch_exception
|
9
10
|
end
|
10
11
|
self.default_logger = Logger.new(STDOUT)
|
11
|
-
self.catch_exception = false
|
12
12
|
|
13
13
|
def initialize(object, method, call_args, **opts)
|
14
14
|
@object = object
|
15
15
|
@method = method
|
16
16
|
@call_args = call_args
|
17
|
+
|
18
|
+
@cleaner = opts[:backtrace_cleaner] || CallLogger.backtrace_cleaner
|
17
19
|
@logger = opts[:logger] || CallLogger.default_logger
|
18
|
-
@tag_proc = opts[:with] || ->{}
|
20
|
+
@tag_proc = opts[:with] || -> {}
|
19
21
|
end
|
20
22
|
|
21
|
-
attr_reader :object, :method, :call_args, :logger, :tag_proc
|
23
|
+
attr_reader :object, :method, :call_args, :logger, :tag_proc, :cleaner
|
22
24
|
|
23
25
|
def self.applier_method
|
24
26
|
:log_calls_to
|
@@ -28,7 +30,7 @@ module Advisor
|
|
28
30
|
logger.info(success_message)
|
29
31
|
yield
|
30
32
|
rescue exception_class => e
|
31
|
-
logger.
|
33
|
+
logger.error(failure_message(e))
|
32
34
|
raise
|
33
35
|
end
|
34
36
|
|
@@ -40,6 +42,7 @@ module Advisor
|
|
40
42
|
|
41
43
|
def failure_message(ex)
|
42
44
|
backtrace = ["\n", ex.to_s] + ex.backtrace
|
45
|
+
backtrace = cleaner.clean(backtrace) if cleaner
|
43
46
|
call_message('Failed: ', backtrace.join("\n"))
|
44
47
|
end
|
45
48
|
|
data/lib/advisor/version.rb
CHANGED
@@ -46,12 +46,10 @@ Called: OpenStruct#the_meaning_of_life(\"the universe\", \"and everything\")"
|
|
46
46
|
everything\"\).*/
|
47
47
|
end
|
48
48
|
|
49
|
-
let(:error_message) { /deu ruim!/ }
|
50
|
-
|
51
49
|
let(:catch_exception) { false }
|
52
50
|
|
53
51
|
before do
|
54
|
-
allow(logger).to receive(:
|
52
|
+
allow(logger).to receive(:error)
|
55
53
|
allow(CallLogger).to receive(:catch_exception)
|
56
54
|
.and_return(catch_exception)
|
57
55
|
end
|
@@ -59,22 +57,20 @@ Called: OpenStruct#the_meaning_of_life(\"the universe\", \"and everything\")"
|
|
59
57
|
it { expect { call }.to raise_error(StandardError, 'deu ruim!') }
|
60
58
|
|
61
59
|
it do
|
62
|
-
expect(logger).to receive(:
|
60
|
+
expect(logger).to receive(:error).with(log_message)
|
63
61
|
expect { call }.to raise_error
|
64
62
|
end
|
65
63
|
|
66
64
|
it do
|
67
|
-
expect(logger).to receive(:
|
65
|
+
expect(logger).to receive(:error).with(log_message)
|
68
66
|
expect { call }.to raise_error
|
69
67
|
end
|
70
68
|
|
71
69
|
context 'when the error is not a StandardError' do
|
72
70
|
let(:block) { -> { fail Exception, 'deu muito ruim!' } }
|
73
71
|
|
74
|
-
let(:error_message) { /deu muito ruim!/ }
|
75
|
-
|
76
72
|
it do
|
77
|
-
expect(logger).not_to receive(:
|
73
|
+
expect(logger).not_to receive(:error).with(log_message)
|
78
74
|
expect { call }.to raise_error(Exception, 'deu muito ruim!')
|
79
75
|
end
|
80
76
|
|
@@ -82,12 +78,12 @@ Called: OpenStruct#the_meaning_of_life(\"the universe\", \"and everything\")"
|
|
82
78
|
let(:catch_exception) { true }
|
83
79
|
|
84
80
|
it do
|
85
|
-
expect(logger).to receive(:
|
81
|
+
expect(logger).to receive(:error).with(log_message)
|
86
82
|
expect { call }.to raise_error(Exception, 'deu muito ruim!')
|
87
83
|
end
|
88
84
|
|
89
85
|
it do
|
90
|
-
expect(logger).to receive(:
|
86
|
+
expect(logger).to receive(:error).with(log_message)
|
91
87
|
expect { call }.to raise_error(Exception, 'deu muito ruim!')
|
92
88
|
end
|
93
89
|
end
|
@@ -96,7 +92,7 @@ Called: OpenStruct#the_meaning_of_life(\"the universe\", \"and everything\")"
|
|
96
92
|
|
97
93
|
context 'when no custom tag is provided' do
|
98
94
|
let(:tag) {}
|
99
|
-
let(:log_without_custom_tag) { log_message.gsub(
|
95
|
+
let(:log_without_custom_tag) { log_message.gsub('[x=y]', '') }
|
100
96
|
|
101
97
|
it do
|
102
98
|
expect(logger).to receive(:info).with(log_without_custom_tag)
|
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.5.
|
4
|
+
version: 0.5.1
|
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-
|
11
|
+
date: 2015-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: metriks
|