Guest User

Untitled

a guest
Mar 15th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. def normalize_uri(uri_or_options)
  2. if String === uri_or_options
  3. uri_or_options = Addressable::URI.parse(uri_or_options)
  4. end
  5. if Addressable::URI === uri_or_options
  6. return uri_or_options.normalize
  7. end
  8.  
  9. adapter = uri_or_options.delete(:adapter)
  10. user = uri_or_options.delete(:username)
  11. password = uri_or_options.delete(:password)
  12. host = (uri_or_options.delete(:host) || "")
  13. port = uri_or_options.delete(:port)
  14. database = uri_or_options.delete(:database)
  15. query = uri_or_options.to_a.map { |pair| pair.join('=') }.join('&')
  16. query = nil if query == ""
  17.  
  18. return Addressable::URI.new(
  19. adapter, user, password, host, port, database, query, nil
  20. )
  21. end
Add Comment
Please, Sign In to add comment