after_do-logging 0.2.1 → 0.3.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da3555e036d927fd741c6319e965c274f1d06dfd
|
4
|
+
data.tar.gz: 2c729b12e68bbbc5c7759b821e18aa8f298209d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 348a829086e308fa23485aae715ed21d8f7f255cc37c48eba23d360c1cf98ce87ade869b3d688e9d960322237438eaa78214915f146bf8b3b5e01d95bbc7b5a6
|
7
|
+
data.tar.gz: 96ff4b34cfa627ebba28583f19bdc72468353fafb086cc091f3f2051758f061b22a5473dddb4885539e2fe2ac84bb6756bb3844dee10ba220b2964e0b6045aaf
|
data/README.md
CHANGED
data/lib/after_do/logging.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
module AfterDo
|
2
|
+
module Logging
|
3
|
+
class StateTransitionAspect
|
4
|
+
def initialize(target_class, logger = AfterDo::Logging.logger)
|
5
|
+
@target_class = target_class
|
6
|
+
@logger = logger
|
7
|
+
end
|
8
|
+
|
9
|
+
def log_start(target_method)
|
10
|
+
target_class.before target_method do |*args, object|
|
11
|
+
method = "#{target_class}##{target_method}"
|
12
|
+
|
13
|
+
msg = "Started #{id(object)}transition from #{object.status} " \
|
14
|
+
" with #{method}#{format_args(args)}"
|
15
|
+
logger.info(msg)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def log_finish(target_method)
|
20
|
+
target_class.after target_method do |*args, object|
|
21
|
+
method = "#{target_class}##{target_method}"
|
22
|
+
|
23
|
+
msg = "Finished #{id(object)}transition to #{object.status} " \
|
24
|
+
"with #{method}#{format_args(args)}"
|
25
|
+
logger.info(msg)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
attr_reader :target_class, :logger
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def format_args(args)
|
36
|
+
"(#{args.join(', ')})" if args.any?
|
37
|
+
end
|
38
|
+
|
39
|
+
def id(object)
|
40
|
+
"[#{object.id}] " if object.respond_to?(:id)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module AfterDo::Logging
|
2
|
+
describe StateTransitionAspect do
|
3
|
+
subject(:aspect) { described_class.new(klass, logger) }
|
4
|
+
|
5
|
+
let(:klass) do
|
6
|
+
Class.new do
|
7
|
+
extend(AfterDo)
|
8
|
+
|
9
|
+
def status; end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
let(:method) { :inspect }
|
13
|
+
let(:logger) { double(:logger, info: nil) }
|
14
|
+
|
15
|
+
describe '#log_start' do
|
16
|
+
subject(:log_start) { aspect.log_start(method) }
|
17
|
+
|
18
|
+
it 'applies the advice before target method invocation' do
|
19
|
+
expect(klass).to receive(:before).with(method)
|
20
|
+
|
21
|
+
log_start
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'calls logger when instance invokes advised method' do
|
25
|
+
expect(logger).to receive(:info)
|
26
|
+
|
27
|
+
log_start
|
28
|
+
klass.new.inspect
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#log_finish' do
|
33
|
+
subject(:log_finish) { aspect.log_finish(method) }
|
34
|
+
|
35
|
+
it 'applies the advice after target method invocation' do
|
36
|
+
expect(klass).to receive(:after).with(method)
|
37
|
+
|
38
|
+
log_finish
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'calls logger when instance invokes advised method' do
|
42
|
+
expect(logger).to receive(:info)
|
43
|
+
|
44
|
+
log_finish
|
45
|
+
klass.new.inspect
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: after_do-logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael da Silva
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-09-
|
12
|
+
date: 2014-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: after_do
|
@@ -100,8 +100,10 @@ files:
|
|
100
100
|
- after_do-logging.gemspec
|
101
101
|
- lib/after_do/logging.rb
|
102
102
|
- lib/after_do/logging/aspect.rb
|
103
|
+
- lib/after_do/logging/state_transition_aspect.rb
|
103
104
|
- lib/after_do/logging/version.rb
|
104
105
|
- spec/after_do/logging/aspect_spec.rb
|
106
|
+
- spec/after_do/logging/state_transition_aspect_spec.rb
|
105
107
|
- spec/after_do/logging_spec.rb
|
106
108
|
- spec/spec_helper.rb
|
107
109
|
homepage: ''
|
@@ -130,6 +132,7 @@ specification_version: 4
|
|
130
132
|
summary: After do aspect for logging method start and finish.
|
131
133
|
test_files:
|
132
134
|
- spec/after_do/logging/aspect_spec.rb
|
135
|
+
- spec/after_do/logging/state_transition_aspect_spec.rb
|
133
136
|
- spec/after_do/logging_spec.rb
|
134
137
|
- spec/spec_helper.rb
|
135
138
|
has_rdoc:
|