class Reindexer::Client
Constants
- DEFAULT_PORT
Attributes
config[R]
connection[R]
Public Class Methods
build_request_name(name)
click to toggle source
# File lib/reindexer/client.rb, line 12 def self.build_request_name(name) name.to_s.gsub(/(.)([A-Z])/, '\1_\2').downcase.to_sym end
new(options)
click to toggle source
# File lib/reindexer/client.rb, line 39 def initialize(options) @config = parse_config(options) @connection = ::Reindexer::Grpc::Reindexer::Stub.new( "#{config[:host]}:#{config[:port] || DEFAULT_PORT}", :this_channel_is_insecure ) end
Private Instance Methods
build_grpc_option_value(field_descriptor, value)
click to toggle source
# File lib/reindexer/client.rb, line 86 def build_grpc_option_value(field_descriptor, value) type = field_descriptor.type if type == :message build_grpc_request(field_descriptor.subtype.msgclass, **value) elsif field_descriptor.name == :data && type == :bytes json_adapter.dump(value) else value end end
build_grpc_request(request_klass, **options)
click to toggle source
# File lib/reindexer/client.rb, line 74 def build_grpc_request(request_klass, **options) request_options = request_klass.descriptor.each_with_object({}) do |field_descriptor, accum| name = field_descriptor.name key_name = [name.to_sym, self.class.build_request_name(name)].find { |n| options.key?(n) } next if key_name.nil? accum[name] = build_grpc_option_value(field_descriptor, options[key_name]) end request_klass.new(**request_options) end
grpc_call(grpc_method, request)
click to toggle source
# File lib/reindexer/client.rb, line 70 def grpc_call(grpc_method, request) @connection.send(grpc_method, request) end
json_adapter()
click to toggle source
# File lib/reindexer/client.rb, line 49 def json_adapter @json_adapter ||= config.fetch(:adapter, JSON) end
parse_config(options)
click to toggle source
# File lib/reindexer/client.rb, line 53 def parse_config(options) case options when String uri = URI(options) { host: uri.host, port: uri.port, scheme: uri.scheme.to_sym, database: uri.path.gsub(%r{^/}, '') } when Hash config.slice(:host, :port, :scheme, :database, :json_adapter) else raise 'Can not parse Reindexer config' end end