Class: ElasticAdapter::Decoration::ResponseDecoratorFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_adapter/decoration/response_decorator_factory.rb

Overview

This class is used inside the Response and is used to determin the decorator for responses returned by elasticsearch

See Also:

Class Method Summary collapse

Class Method Details

.decorate(response) ⇒ Docorator

Takes a response and returns it with the right decorator applied


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/elastic_adapter/decoration/response_decorator_factory.rb', line 14

def decorate(response)
  if response.key? :count
    return CountResponse.new(response)
  elsif response.key? :source
    return HitDecorator.new(response)
  elsif response.key? :hits
    return SearchResponse.new(response)
  elsif response.key? :valid
    return ValidationResponse.new(response)
  elsif suggestion?(response)
    return SuggestionResponse.new(response)
  end

  response
end