Created
September 10, 2012 20:24
-
-
Save veader/3693592 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# monkey patch resolver to properly decode URI encoded attributes | |
class ActiveRecord::Base::ConnectionSpecification | |
class Resolver | |
private | |
def connection_url_to_hash(url) | |
config = URI.parse url | |
adapter = config.scheme | |
adapter = "postgresql" if adapter == "postgres" | |
spec = { :adapter => adapter, | |
:username => config.user, | |
:password => config.password, | |
:port => config.port, | |
:database => config.path.sub(%r{^/},""), | |
:host => config.host } | |
spec.reject!{ |_,value| !value } | |
# decode any encoded params | |
spec.each { |k,v| spec[k] = URI.decode(v) if v.is_a?(String) } | |
if config.query | |
arr = config.query.split("&").map{ |pair| pair.split("=") } | |
options = Hash[arr].symbolize_keys | |
spec.merge!(options) | |
end | |
spec | |
end | |
end # Resolver | |
end # ConnectionSpecification |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment