Sha256: abb0b0fb6754a4e765f951aec07dad4c7971e9e27095e20dc6489abb15fcc9c5

Contents?: true

Size: 1.01 KB

Versions: 11

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'proxes/request'
require 'proxes/policies/request/bulk_policy'

module ProxES
  class Request
    class Bulk < Request
      attr_reader :index, :type

      REGEX = /"(index|delete|create|update)".*"_index"\s*:\s*"(.*?)"/

      def bulk_indices
        @bulk_indices ||= begin
          body.read.scan(REGEX).tap { |_r| body.rewind }
        end.map { |e| e[1] }.uniq
      end

      def index=(idx)
        @index = idx
        self.path_info = '/' + [index, type, endpoint].compact
                                                      .map { |v| v.is_a?(Array) ? v.join(',') : v }
                                                      .select { |v| !v.nil? && v != '' }.join('/')
      end

      def endpoint
        '_bulk'
      end

      def parse
        @index ||= check_part(path_parts[0]) unless path_parts[0] == endpoint
        @type  ||= check_part(path_parts[1]) unless path_parts[1] == endpoint
      end

      def indices?
        !@index.nil?
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
proxes-0.9.13 lib/proxes/request/bulk.rb
proxes-0.9.12 lib/proxes/request/bulk.rb
proxes-0.9.9 lib/proxes/request/bulk.rb
proxes-0.9.7 lib/proxes/request/bulk.rb
proxes-0.9.4 lib/proxes/request/bulk.rb
proxes-0.9.2 lib/proxes/request/bulk.rb
proxes-0.9.1 lib/proxes/request/bulk.rb
proxes-0.9.0 lib/proxes/request/bulk.rb
proxes-0.8.6 lib/proxes/request/bulk.rb
proxes-0.8.5 lib/proxes/request/bulk.rb
proxes-0.8.4 lib/proxes/request/bulk.rb