Class: RedisClient::URLConfig
- Inherits:
-
Object
- Object
- RedisClient::URLConfig
- Defined in:
- lib/redis_client/url_config.rb
Constant Summary collapse
- DEFAULT_SCHEMA =
"redis"
- SSL_SCHEMA =
"rediss"
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #db ⇒ Object
- #host ⇒ Object
-
#initialize(url) ⇒ URLConfig
constructor
A new instance of URLConfig.
- #password ⇒ Object
- #port ⇒ Object
- #ssl? ⇒ Boolean
- #username ⇒ Object
Constructor Details
#initialize(url) ⇒ URLConfig
Returns a new instance of URLConfig.
12 13 14 15 16 17 18 |
# 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 |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
10 11 12 |
# File 'lib/redis_client/url_config.rb', line 10 def uri @uri end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/redis_client/url_config.rb', line 10 def url @url end |
Instance Method Details
#db ⇒ Object
24 25 26 27 |
# 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 ⇒ Object
41 42 43 44 45 |
# 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 ⇒ Object
33 34 35 36 37 38 39 |
# 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 ⇒ Object
47 48 49 50 51 |
# File 'lib/redis_client/url_config.rb', line 47 def port return unless uri.port Integer(uri.port) end |
#ssl? ⇒ Boolean
20 21 22 |
# File 'lib/redis_client/url_config.rb', line 20 def ssl? @uri.scheme == SSL_SCHEMA end |
#username ⇒ Object
29 30 31 |
# File 'lib/redis_client/url_config.rb', line 29 def username uri.user if uri.password && !uri.user.empty? end |