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, line 79 def self.append_to_uri_path(uri, path) return uri if path == "" new_uri = uri.clone new_uri.path = "#{uri.path}/#{path}" new_uri 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, line 105 def self.get_path_leaf_from_uri(uri) path = uri.path.split("/")[-1] path.nil? ? "" : path 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, line 93 def self.replace_uri_path(uri, path) new_uri = uri.clone new_uri.path = path new_uri 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, line 71 def self.strip_path_slashes(path) path.gsub(/^\//, "").chomp("/") 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, line 49 def self.strip_uri_credentials(uri) # we want to use URIs here but strings can be passed in uri = URI.parse(Util.strip_path_slashes(uri)) unless uri.is_a? URI creds = nil # strip username and password from the URI if present if uri.user != nil creds = T2Server::HttpBasic.new(uri.user, uri.password) uri = URI::HTTP.new(uri.scheme, nil, uri.host, uri.port, nil, uri.path, nil, nil, nil); end [uri, creds] end