Class: RedisClient::URLConfig
- Inherits:
-
Object
- Object
- RedisClient::URLConfig
- Defined in:
- lib/redis_client/url_config.rb
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
- #path ⇒ Object
- #port ⇒ Object
- #ssl? ⇒ Boolean
- #username ⇒ Object
Constructor Details
#initialize(url) ⇒ URLConfig
Returns a new instance of URLConfig.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/redis_client/url_config.rb', line 9 def initialize(url) @url = url @uri = URI(url) @unix = false @ssl = false case uri.scheme when "redis" # expected when "rediss" @ssl = true when "unix", nil @unix = true else raise ArgumentError, "Unknown URL scheme: #{url.inspect}" end end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/redis_client/url_config.rb', line 7 def uri @uri end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/redis_client/url_config.rb', line 7 def url @url end |
Instance Method Details
#db ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/redis_client/url_config.rb', line 30 def db unless @unix db_path = uri.path&.delete_prefix("/") return Integer(db_path) if db_path && !db_path.empty? end unless uri.query.nil? || uri.query.empty? _, db_query = URI.decode_www_form(uri.query).find do |key, _| key == "db" end return Integer(db_query) if db_query && !db_query.empty? end end |
#host ⇒ Object
56 57 58 59 60 |
# File 'lib/redis_client/url_config.rb', line 56 def host return if uri.host.nil? || uri.host.empty? uri.host.sub(/\A\[(.*)\]\z/, '\1') end |
#password ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/redis_client/url_config.rb', line 48 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 |
#path ⇒ Object
62 63 64 65 66 |
# File 'lib/redis_client/url_config.rb', line 62 def path if @unix File.join(*[uri.host, uri.path].compact) end end |
#port ⇒ Object
68 69 70 71 72 |
# File 'lib/redis_client/url_config.rb', line 68 def port return unless uri.port Integer(uri.port) end |
#ssl? ⇒ Boolean
26 27 28 |
# File 'lib/redis_client/url_config.rb', line 26 def ssl? @ssl end |
#username ⇒ Object
44 45 46 |
# File 'lib/redis_client/url_config.rb', line 44 def username uri.user if uri.password && !uri.user.empty? end |