Sha256: c9efca32d9394f8cde6adb1a47c3620912f85ccd632f58a6a84609ca1d1403f9

Contents?: true

Size: 1003 Bytes

Versions: 5

Compression:

Stored size: 1003 Bytes

Contents

module Elastic::Nodes::Concerns
  module HitProvider
    attr_accessor :size
    attr_reader :source

    def source=(_values)
      case _values
      when nil, false
        @source = _values
      when Array, Enumerable
        @source = _values.dup.to_a
      else
        raise ArgumentError, 'invalid query source value'
      end
    end

    def clone
      copy_hit_options super
    end

    def simplify
      copy_hit_options super
    end

    private

    def prepare_hits(_hits, _formatter)
      _hits.map do |raw_hit|
        Elastic::Results::Hit.new(
          raw_hit['_id'],
          raw_hit['_score'],
          raw_hit['_source'] ? _formatter.format(raw_hit['_source']) : nil
        )
      end
    end

    def copy_hit_options(_clone)
      _clone.size = @size
      _clone.source = @source
      _clone
    end

    def render_hit_options(_hash)
      _hash['size'] = @size unless @size.nil?
      _hash["_source"] = @source unless @source.nil?
      _hash
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
elastic-rails-1.0.4 lib/elastic/nodes/concerns/hit_provider.rb
elastic-rails-1.0.3 lib/elastic/nodes/concerns/hit_provider.rb
elastic-rails-1.0.2 lib/elastic/nodes/concerns/hit_provider.rb
elastic-rails-1.0.1 lib/elastic/nodes/concerns/hit_provider.rb
elastic-rails-1.0.0 lib/elastic/nodes/concerns/hit_provider.rb