Skip to content

Instantly share code, notes, and snippets.

@veader
Created September 10, 2012 20:24
Show Gist options
  • Save veader/3693592 to your computer and use it in GitHub Desktop.
Save veader/3693592 to your computer and use it in GitHub Desktop.
# 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