module T2Server::Util
This module contains various utility methods that the library uses internally.
Public Class Methods
append_to_uri_path(uri, path) → URI
click to toggle source
Appends a path to the end of the path of the given URI.
# File lib/t2-server/util.rb 79 def self.append_to_uri_path(uri, path) 80 return uri if path == "" 81 82 new_uri = uri.clone 83 new_uri.path = "#{uri.path}/#{path}" 84 85 new_uri 86 end
get_path_leaf_from_uri(uri) → string
click to toggle source
Get the final component from the path of a URI. This method returns the empty string (not nil ) if the URI does not have a path.
# File lib/t2-server/util.rb 105 def self.get_path_leaf_from_uri(uri) 106 path = uri.path.split("/")[-1] 107 108 path.nil? ? "" : path 109 end
replace_uri_path(uri, path) → URI
click to toggle source
Replace the given URI's path with a new one. The new path must be an absolute path (start with a slash).
# File lib/t2-server/util.rb 93 def self.replace_uri_path(uri, path) 94 new_uri = uri.clone 95 new_uri.path = path 96 97 new_uri 98 end
strip_path_slashes(path) → string
click to toggle source
Returns a new String with one leading and one trailing slash removed from the ends of path (if present).
# File lib/t2-server/util.rb 71 def self.strip_path_slashes(path) 72 path.gsub(/^\//, "").chomp("/") 73 end
strip_uri_credentials(uri) → URI, HttpBasic
click to toggle source
Strip user credentials from an address in URI or String format and return a tuple of the URI minus the credentials and a T2Server::HttpBasic
object.
# File lib/t2-server/util.rb 49 def self.strip_uri_credentials(uri) 50 # we want to use URIs here but strings can be passed in 51 uri = URI.parse(Util.strip_path_slashes(uri)) unless uri.is_a? URI 52 53 creds = nil 54 55 # strip username and password from the URI if present 56 if uri.user != nil 57 creds = T2Server::HttpBasic.new(uri.user, uri.password) 58 59 uri = URI::HTTP.new(uri.scheme, nil, uri.host, uri.port, nil, 60 uri.path, nil, nil, nil); 61 end 62 63 [uri, creds] 64 end