Sha256: e8bb156b618484d146f8b137e9008a326af5067ae1f18b881650cef9ac7c3d7f

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 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_actions
      end

      def bulk_indices
        @bulk_indices ||= begin
          body.read.scan REGEX
        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

1 entries across 1 versions & 1 rubygems

Version Path
proxes-0.8.3 lib/proxes/request/bulk.rb