class RedisClient::URLConfig

Constants

DEFAULT_SCHEMA
SSL_SCHEMA

Attributes

uri[R]
url[R]

Public Class Methods

new(url) click to toggle source
# File lib/redis_client/url_config.rb, line 12
def initialize(url)
  @url = url
  @uri = URI(url)
  unless uri.scheme == DEFAULT_SCHEMA || uri.scheme == SSL_SCHEMA
    raise ArgumentError, "Invalid URL: #{url.inspect}"
  end
end

Public Instance Methods

db() click to toggle source
# File lib/redis_client/url_config.rb, line 24
def db
  db_path = uri.path&.delete_prefix("/")
  Integer(db_path) if db_path && !db_path.empty?
end
host() click to toggle source
# File lib/redis_client/url_config.rb, line 41
def host
  return if uri.host.nil? || uri.host.empty?

  uri.host.sub(/\A\[(.*)\]\z/, '\1')
end
password() click to toggle source
# File lib/redis_client/url_config.rb, line 33
def password
  if uri.user && !uri.password
    URI.decode_www_form_component(uri.user)
  elsif uri.user && uri.password
    URI.decode_www_form_component(uri.password)
  end
end
port() click to toggle source
# File lib/redis_client/url_config.rb, line 47
def port
  return unless uri.port

  Integer(uri.port)
end
ssl?() click to toggle source
# File lib/redis_client/url_config.rb, line 20
def ssl?
  @uri.scheme == SSL_SCHEMA
end
username() click to toggle source
# File lib/redis_client/url_config.rb, line 29
def username
  uri.user if uri.password && !uri.user.empty?
end