Class: Elasticsearch::API::Response
- Inherits:
-
Object
- Object
- Elasticsearch::API::Response
show all
- Defined in:
- lib/elasticsearch/api/response.rb
Overview
Elasticsearch client API Response object. Receives an Elastic::Transport::Transport::Response in the initializer and behaves like a Hash, except when status or headers are called upon it, in which case it returns the original object’s status and headers.
Constant Summary
collapse
- RESPONSE_METHODS =
[:status, :body, :headers]
Instance Method Summary
collapse
Constructor Details
#initialize(response) ⇒ Response
26
27
28
|
# File 'lib/elasticsearch/api/response.rb', line 26
def initialize(response)
@response = response
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/elasticsearch/api/response.rb', line 30
def method_missing(method, *args, &block)
if RESPONSE_METHODS.include? method
@response.send method.to_sym
else
@response.body.send(method.to_sym, *args, &block)
end
end
|
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
38
39
40
41
|
# File 'lib/elasticsearch/api/response.rb', line 38
def respond_to_missing?(method_name, include_private = false)
@response.body.respond_to?(method_name, include_private) ||
RESPONSE_METHODS.include?(method_name)
end
|
#to_s ⇒ Object
43
44
45
|
# File 'lib/elasticsearch/api/response.rb', line 43
def to_s
@response.body.to_s
end
|