method_decorator 1.0.0 → 1.1.0
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/README.rdoc +3 -12
- data/lib/method_decorator/version.rb +1 -1
- data/lib/method_decorator.rb +5 -0
- data/spec/support/some_class.rb +4 -6
- 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: be0a9514d16986f1226824039aae623898876f14
|
4
|
+
data.tar.gz: bfa76543251a5212967d7b524a4800b468857239
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0d4e40c492f07d3ded55ba928723c5568b17e6cc8498bcb962e7e69a96d135a95f8876e33a11f1ad461bc5ccfa1a145d3d897664cb2a847de4ce6baa817e64e
|
7
|
+
data.tar.gz: ff8757256465330b96ae9c29bb7b079f3c86c02c5f1162cccee13f08d5d94a89c3bdd976b1dd11b77b892d0e4268b12164a56c0c49dd69b874a3944af1b35b24
|
data/README.rdoc
CHANGED
@@ -15,10 +15,9 @@ For a given class (with unnecessary complex logic, just to make a point):
|
|
15
15
|
include MethodDecorator
|
16
16
|
|
17
17
|
method_to_override = :some_method
|
18
|
-
|
19
|
-
decorate_method method_to_override do |some_arg|
|
18
|
+
decorate_method method_to_override do |*args|
|
20
19
|
puts :decorated_some_method
|
21
|
-
|
20
|
+
call_original_method method_to_override, *args
|
22
21
|
end
|
23
22
|
|
24
23
|
end
|
@@ -30,12 +29,4 @@ This call:
|
|
30
29
|
Produces this output:
|
31
30
|
|
32
31
|
decorated_some_method
|
33
|
-
some arg
|
34
|
-
|
35
|
-
== Next moves
|
36
|
-
|
37
|
-
- Find a better way to call the original method, for now it's too verbose
|
38
|
-
|
39
|
-
original_method_name = original_method_name_for(:some_method)
|
40
|
-
...
|
41
|
-
send original_method_name, some_arg
|
32
|
+
some arg
|
data/lib/method_decorator.rb
CHANGED
@@ -23,6 +23,11 @@ module MethodDecorator extend ActiveSupport::Concern
|
|
23
23
|
|
24
24
|
end
|
25
25
|
|
26
|
+
def call_original_method(target, *args, &block)
|
27
|
+
original_method_name = self.singleton_class.original_method_name_for target
|
28
|
+
send original_method_name, *args, &block
|
29
|
+
end
|
30
|
+
|
26
31
|
end
|
27
32
|
|
28
33
|
end
|
data/spec/support/some_class.rb
CHANGED
@@ -7,10 +7,9 @@ class SomeClass
|
|
7
7
|
include MethodDecorator
|
8
8
|
|
9
9
|
method_to_override = :some_method
|
10
|
-
|
11
|
-
decorate_method method_to_override do |some_arg|
|
10
|
+
decorate_method method_to_override do |*args|
|
12
11
|
puts :decorated_some_method
|
13
|
-
|
12
|
+
call_original_method method_to_override, *args
|
14
13
|
end
|
15
14
|
|
16
15
|
class << self
|
@@ -22,10 +21,9 @@ class SomeClass
|
|
22
21
|
include MethodDecorator
|
23
22
|
|
24
23
|
method_to_override = :some_method
|
25
|
-
|
26
|
-
decorate_method method_to_override do |some_arg|
|
24
|
+
decorate_method method_to_override do |*args|
|
27
25
|
puts :decorated_some_method
|
28
|
-
|
26
|
+
call_original_method method_to_override, *args
|
29
27
|
end
|
30
28
|
|
31
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_decorator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- r4z3c
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|