simple_aspect 0.2.0 → 0.2.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/lib/simple_aspect.rb +47 -0
- data/lib/simple_aspect/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4d10294dae057f9b624813a323f1195f33792c7
|
4
|
+
data.tar.gz: 47f0750698a998be89ff0fb06854440fad86ad04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab95a34f6118aa21a8b8cbc260c250331708b47bc63f8d08e5a368515e6a5f55313e25cf688387396968104bfe6b1956ffa5efecd62f3ab15dabb18842a6ed74
|
7
|
+
data.tar.gz: 08daefe1dc62a9d1d0f9a84a79a8c08e994392c22e1a59395f21a559ba0cdc3e5a9bf68e6792829485e4ae56d85831907ca920fbe419f4ef56eaf1d210fed9e7
|
data/lib/simple_aspect.rb
CHANGED
@@ -3,6 +3,7 @@ require 'simple_aspect/version'
|
|
3
3
|
module SimpleAspect
|
4
4
|
require 'thread'
|
5
5
|
|
6
|
+
# @api private
|
6
7
|
def self.extended(base)
|
7
8
|
base.instance_eval do
|
8
9
|
@sa_methods_to_aspect_methods_name = {}
|
@@ -11,6 +12,51 @@ module SimpleAspect
|
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
15
|
+
# Register an aspect method around the target method
|
16
|
+
#
|
17
|
+
# @param method [Symbol] name of the target method
|
18
|
+
# @param instance_around_method_name [Symbol] name of the aspect method. If
|
19
|
+
# not provided, the definition of the aspect method should be provided with
|
20
|
+
# a Proc/lambda
|
21
|
+
# @param block [Proc] the definition of the aspect method if its name was not
|
22
|
+
# provided. This Proc needs to receive two arguments: *orig_args,
|
23
|
+
# &orig_block
|
24
|
+
#
|
25
|
+
# @example without a defined method
|
26
|
+
# class Worker
|
27
|
+
# extend SimpleAspect
|
28
|
+
#
|
29
|
+
# aspect_around :perform do |*args, &original|
|
30
|
+
# result = original.call
|
31
|
+
# log(result)
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# def perform(*args)
|
35
|
+
# # do_work
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# def log(message)
|
39
|
+
# # log
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# @example with a defined method
|
44
|
+
#
|
45
|
+
# class Worker
|
46
|
+
# extend SimpleAspect
|
47
|
+
#
|
48
|
+
# aspect_around :perform, :log
|
49
|
+
#
|
50
|
+
# def perform(*args)
|
51
|
+
# # do_work
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# def log(*args)
|
55
|
+
# # log *args
|
56
|
+
# result = yield
|
57
|
+
# # log result
|
58
|
+
# end
|
59
|
+
# end
|
14
60
|
def aspect_around(
|
15
61
|
method,
|
16
62
|
instance_around_method_name = sa_instance_around_method_name(method),
|
@@ -19,6 +65,7 @@ module SimpleAspect
|
|
19
65
|
sa_register_aspect_on_method(method, instance_around_method_name, &block)
|
20
66
|
end
|
21
67
|
|
68
|
+
# @api private
|
22
69
|
def method_added(method)
|
23
70
|
return if sa_should_not_redefine?(method)
|
24
71
|
|