Sha256: 6f9fa089acf33674a9e7002b644cc0a2688fa27edd69f7b24dda383d2779b7a3

Contents?: true

Size: 760 Bytes

Versions: 3

Compression:

Stored size: 760 Bytes

Contents

module Elastics
  class Result < ::Hash

    attr_reader :template, :response
    attr_accessor :variables

    def initialize(template, variables, response, raw_result=nil)
      @template  = template
      @variables = variables
      @response  = response
      replace raw_result || !response.body.empty? && MultiJson.decode(response.body) || return
      Conf.result_extenders.each do |ext|
        next if ext.respond_to?(:should_extend?) && !ext.should_extend?(self)
        extend ext
      end
    end

    def to_elastics_result(force=false)
      return self if variables[:context].nil? || variables[:raw_result] &&! force
      variables[:context].respond_to?(:elastics_result) ? variables[:context].elastics_result(self) : self
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
elastics-client-1.3.3 lib/elastics/result.rb
elastics-client-1.3.2 lib/elastics/result.rb
elastics-client-1.3.1 lib/elastics/result.rb