forked from elastic/elasticsearch-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforwardable.rb
35 lines (31 loc) · 990 Bytes
/
forwardable.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module Elasticsearch
module Model
module Support
# Lightweight wrapper around "forwardable.rb" interface,
# to allow easy delegation implementation changes in the future.
#
# Cf. https://github.com/mongoid/origin/blob/master/lib/origin/forwardable.rb
#
module Forwardable
def self.extended(base)
base.__send__ :extend, ::Forwardable
end
# Forwards specific method(s) to the provided receiver
#
# @example Forward the `each` method to `results` object
#
# MyClass.forward(:results, :each)
#
# @param [ Symbol ] receiver The name of the receiver method
# @param [ Symbol, Array ] methods The forwarded methods
#
# @api private
#
def forward(receiver, *methods)
methods = Array(methods).flatten
def_delegators receiver, *methods
end; module_function :forward
end
end
end
end