File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
lib/elasticsearch/model/response Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -22,9 +22,9 @@ def initialize(attributes={})
22
22
def method_missing ( method_name , *arguments )
23
23
case
24
24
when @result . respond_to? ( method_name . to_sym )
25
- @result [ method_name . to_sym ]
25
+ @result . __send__ method_name . to_sym , * arguments
26
26
when @result . _source && @result . _source . respond_to? ( method_name . to_sym )
27
- @result . _source [ method_name . to_sym ]
27
+ @result . _source . __send__ method_name . to_sym , * arguments
28
28
else
29
29
super
30
30
end
@@ -33,8 +33,8 @@ def method_missing(method_name, *arguments)
33
33
# Respond to methods from `@result` or `@result._source`
34
34
#
35
35
def respond_to? ( method_name , include_private = false )
36
- @result . has_key ?( method_name . to_sym ) || \
37
- @result . _source && @result . _source . has_key ?( method_name . to_sym ) || \
36
+ @result . respond_to ?( method_name . to_sym ) || \
37
+ @result . _source && @result . _source . respond_to ?( method_name . to_sym ) || \
38
38
super
39
39
end
40
40
Original file line number Diff line number Diff line change @@ -27,5 +27,18 @@ class Elasticsearch::Model::ResultTest < Test::Unit::TestCase
27
27
assert_equal 'baz' , result . bar
28
28
end
29
29
30
+ should "delegate methods to @result" do
31
+ result = Elasticsearch ::Model ::Response ::Result . new foo : 'bar'
32
+
33
+ assert_equal 'bar' , result . foo
34
+ assert_equal 'bar' , result . fetch ( 'foo' )
35
+ assert_equal 'moo' , result . fetch ( 'NOT_EXIST' , 'moo' )
36
+
37
+ assert_respond_to result , :to_hash
38
+ assert_equal ( { 'foo' => 'bar' } , result . to_hash )
39
+
40
+ assert_raise ( NoMethodError ) { result . does_not_exist }
41
+ end
42
+
30
43
end
31
44
end
You can’t perform that action at this time.
0 commit comments