class Realm::Elasticsearch::Gateway

Public Class Methods

new(url:, **options) click to toggle source
# File lib/realm/elasticsearch/gateway.rb, line 6
def initialize(url:, **options)
  @url = url
  @client_options = options.slice(:adapter, :retry_on_failure, :request_timeout)
end

Public Instance Methods

health() click to toggle source
# File lib/realm/elasticsearch/gateway.rb, line 11
def health
  issues = []
  index_names = Repository.subclasses.map(&:index_name)
  begin
    issues << 'One or more indexes missing' unless client.indices.exists(index: index_names)
  rescue StandardError => e
    issues << "Elasticsearch connection error: #{e.full_message}"
  end
  HealthStatus.from_issues(issues)
end
method_missing(...) click to toggle source
# File lib/realm/elasticsearch/gateway.rb, line 22
def method_missing(...)
  client.send(...)
end
respond_to_missing?(...) click to toggle source
# File lib/realm/elasticsearch/gateway.rb, line 26
def respond_to_missing?(...)
  client.respond_to?(...)
end

Private Instance Methods

client() click to toggle source
# File lib/realm/elasticsearch/gateway.rb, line 32
def client
  @client ||= ::Elasticsearch::Client.new(default_config.merge(@client_options))
end
default_config() click to toggle source
# File lib/realm/elasticsearch/gateway.rb, line 36
def default_config
  {
    url: @url,
    adapter: :typhoeus,
    retry_on_failure: 3,
    request_timeout: 30,
  }
end