advisor 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07274c88a6cc965df236304e2cadec348a89b609
4
- data.tar.gz: 7008dc31d29852a09368e9f3add2e84e1dc6c61a
3
+ metadata.gz: 1af6e27daaa7ebbfd51db284ddcd77c52cd07e07
4
+ data.tar.gz: 7ea3cccb39ca9c1148c46c0f9502c1b14a4b0b86
5
5
  SHA512:
6
- metadata.gz: 1c3de77e3ba71106ce800367fedf8a49665425b09dc607d243438bd7e3b1e93f1ebd2924f95596567f47d60a5919d327810bcb49527a50d03f0c00de5db9b932
7
- data.tar.gz: bddee9a5ae3777933c009f6c8d911ad188142e2132720174a937072151a39e3708e8f2b8680ae620a7dbc60f4c1878163652545a0b9ccb941e170b0d21679dd4
6
+ metadata.gz: b489ede32c1044532587f88baa1586fe18ac690ec007ba9fc41aa1197bc48359bb010c97c11cdf199fc003fcedd8fca8b3d4a954b42eed17266e6a2955cc581c
7
+ data.tar.gz: 237a4fd3a4aa3beea49ce9f250ab2953f31553512d42de3a920bdfb2ddaf2473adc749e0ff678e86ed09e26d5dbe80c2df26744e22c7ed662af5905c0b8f6792
@@ -15,9 +15,10 @@ module Advisor
15
15
  @method = method
16
16
  @call_args = call_args
17
17
  @logger = opts[:logger] || CallLogger.default_logger
18
+ @tag_proc = opts[:with] || ->{}
18
19
  end
19
20
 
20
- attr_reader :object, :method, :call_args, :logger
21
+ attr_reader :object, :method, :call_args, :logger, :tag_proc
21
22
 
22
23
  def self.applier_method
23
24
  :log_calls_to
@@ -43,7 +44,7 @@ module Advisor
43
44
  end
44
45
 
45
46
  def call_message(prefix, suffix = '')
46
- "#{time}#{thread}#{id}#{prefix}\
47
+ "#{time}#{thread}#{id}#{custom_tag}#{prefix}\
47
48
  #{klass}##{method}(#{arguments})\
48
49
  #{suffix}"
49
50
  end
@@ -56,6 +57,10 @@ module Advisor
56
57
  "[Time=#{Time.now}]"
57
58
  end
58
59
 
60
+ def custom_tag
61
+ object.instance_exec(&tag_proc)
62
+ end
63
+
59
64
  def klass
60
65
  object.class
61
66
  end
@@ -1,3 +1,3 @@
1
1
  module Advisor
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -4,13 +4,14 @@ module Advisor
4
4
  module Advices
5
5
  describe CallLogger do
6
6
  subject(:advice) do
7
- described_class.new(object, method, args, logger: logger)
7
+ described_class.new(object, method, args, logger: logger, with: tag)
8
8
  end
9
9
 
10
- let(:object) { OpenStruct.new(id: 42) }
10
+ let(:object) { OpenStruct.new(id: 42, x: 'y') }
11
11
  let(:method) { 'the_meaning_of_life' }
12
12
  let(:args) { ['the universe', 'and everything'] }
13
13
  let(:logger) { instance_double(Logger) }
14
+ let(:tag) { -> { "[x=#{x}]" } }
14
15
 
15
16
  let(:block) { -> { :bla } }
16
17
 
@@ -18,7 +19,7 @@ module Advisor
18
19
  subject(:call) { advice.call(&block) }
19
20
 
20
21
  let(:log_message) do
21
- "[Time=#{Time.now}][Thread=#{Thread.current.object_id}][id=42]\
22
+ "[Time=#{Time.now}][Thread=#{Thread.current.object_id}][id=42][x=y]\
22
23
  Called: OpenStruct#the_meaning_of_life(\"the universe\", \"and everything\")"
23
24
  end
24
25
 
@@ -39,8 +40,9 @@ Called: OpenStruct#the_meaning_of_life(\"the universe\", \"and everything\")"
39
40
  let(:block) { -> () { fail 'deu ruim!' } }
40
41
 
41
42
  let(:log_message) do
42
- /\[Time=#{Time.now}\]\[Thread=#{Thread.current.object_id}\]\
43
- \[id=42\]Failed: OpenStruct#the_meaning_of_life\(\"the universe\", \"and\
43
+ /\[Time=#{Regexp.quote(Time.now.to_s)}\]\
44
+ \[Thread=#{Thread.current.object_id}\]\
45
+ \[id=42\]\[x=y\]Failed: OpenStruct#the_meaning_of_life\(\"the universe\", \"and\
44
46
  everything\"\).*/
45
47
  end
46
48
 
@@ -91,6 +93,17 @@ Called: OpenStruct#the_meaning_of_life(\"the universe\", \"and everything\")"
91
93
  end
92
94
  end
93
95
  end
96
+
97
+ context 'when no custom tag is provided' do
98
+ let(:tag) {}
99
+ let(:log_without_custom_tag) { log_message.gsub("[x=y]", "") }
100
+
101
+ it do
102
+ expect(logger).to receive(:info).with(log_without_custom_tag)
103
+
104
+ call
105
+ end
106
+ end
94
107
  end
95
108
  end
96
109
  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.4.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-19 00:00:00.000000000 Z
11
+ date: 2015-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metriks