Class: Elasticsearch::Resources::ResponseFactory
- Inherits:
-
Object
- Object
- Elasticsearch::Resources::ResponseFactory
- Defined in:
- lib/elasticsearch/resources/response_factory.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #build ⇒ Object
- #build_get ⇒ Object
- #build_search ⇒ Object
-
#initialize(resource:, action:, response:) ⇒ ResponseFactory
constructor
A new instance of ResponseFactory.
- #resources_for(content) ⇒ Object
Constructor Details
#initialize(resource:, action:, response:) ⇒ ResponseFactory
Returns a new instance of ResponseFactory.
6 7 8 9 10 |
# File 'lib/elasticsearch/resources/response_factory.rb', line 6 def initialize(resource:, action:, response:) @resource = resource @action = action @response = response end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
4 5 6 |
# File 'lib/elasticsearch/resources/response_factory.rb', line 4 def action @action end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
4 5 6 |
# File 'lib/elasticsearch/resources/response_factory.rb', line 4 def resource @resource end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
4 5 6 |
# File 'lib/elasticsearch/resources/response_factory.rb', line 4 def response @response end |
Instance Method Details
#build ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/elasticsearch/resources/response_factory.rb', line 12 def build case action when :get build_get when :search build_search else response end end |
#build_get ⇒ Object
23 24 25 26 27 28 |
# File 'lib/elasticsearch/resources/response_factory.rb', line 23 def build_get DocumentFactory.new( content: response, resources: resources_for(response) ).build end |
#build_search ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/elasticsearch/resources/response_factory.rb', line 30 def build_search raw_documents = response['hits']['hits'] raw_documents.collect do |raw_document| DocumentFactory.new( content: raw_document, resources: resources_for(raw_document) ).build end end |
#resources_for(content) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/elasticsearch/resources/response_factory.rb', line 40 def resources_for(content) { cluster: resource.find_cluster, index: resource.find_index(index: content['_index']), type: resource.find_type(index: content['_index'], type: content['_type']) } end |