File tree 1 file changed +11
-2
lines changed
elasticsearch-model/lib/elasticsearch/model/support
1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ module Support
10
10
module Forwardable
11
11
def self . extended ( base )
12
12
base . __send__ :extend , ::Forwardable
13
+ base . __send__ :extend , ::SingleForwardable
13
14
end
14
15
15
16
# Forwards specific method(s) to the provided receiver
@@ -18,16 +19,24 @@ def self.extended(base)
18
19
#
19
20
# MyClass.forward(:results, :each)
20
21
#
22
+ # @example Forward the `include?` method to `ancestors` class method
23
+ #
24
+ # MyClass.forward(:'self.ancestors', :include?)
25
+ #
21
26
# @param [ Symbol ] receiver The name of the receiver method
22
27
# @param [ Symbol, Array ] methods The forwarded methods
23
28
#
24
29
# @api private
25
30
#
26
31
def forward ( receiver , *methods )
27
32
methods = Array ( methods ) . flatten
33
+ target = self . __send__ :eval , receiver . to_s rescue nil
28
34
29
- def_delegators receiver , *methods
30
-
35
+ if target . is_a? ( Module )
36
+ single_delegate methods => receiver
37
+ else
38
+ instance_delegate methods => receiver
39
+ end
31
40
end ; module_function :forward
32
41
end
33
42
end
You can’t perform that action at this time.
0 commit comments