See: https://www.rubyguides.com/2018/10/delegate-methods-in-ruby/
module Algolia
module Search
# Class Index
class Index
include CallType
extend Forwardable # available in ruby 2.2
attr_reader :index_name, :transporter, :config
def_delegators :@tranporter, :read, :write
end
end
end
The instead of
def search(query, opts: {})
@transporter.read(:POST, "#{@index_uri}/query", body: {'query': query}, opts: opts)
end
def batch(request, opts: {})
@transporter.write(:POST, "#{@index_uri}/batch", body: request, opts: opts)
end
you simply write
def search(query, opts: {})
read(:POST, "#{@index_uri}/query", body: {'query': query}, opts: opts)
end
def batch(request, opts: {})
write(:POST, "#{@index_uri}/batch", body: request, opts: opts)
end