Module: GitHostNormalizer Private
- Defined in:
- lib/spm_version_updates/git_host_normalizer.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Extracts and normalizes hostnames from common git remote URL forms.
Constant Summary collapse
- HOST_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/\A[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?\z/i- BRACKETED_IPV6_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/\A\[(?<address>[^\]]+)\](?::\d+)?\z/
Class Method Summary collapse
- .bare_host(url) ⇒ Object private
- .host(repo_url) ⇒ Object private
- .normalize_host(host) ⇒ Object private
- .normalize_ipv6_address(address) ⇒ Object private
- .normalized_ipv6_host(host) ⇒ Object private
- .parsed_host(url) ⇒ Object private
- .scp_like_host(url) ⇒ Object private
Class Method Details
.bare_host(url) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 34 35 36 |
# File 'lib/spm_version_updates/git_host_normalizer.rb', line 31 def (url) return nil if url.start_with?("/", "./", "../") return nil if url.include?("://") normalize_host(url.split("/", 2).first) end |
.host(repo_url) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 16 17 18 |
# File 'lib/spm_version_updates/git_host_normalizer.rb', line 13 def host(repo_url) url = repo_url.to_s.strip return nil if url.empty? parsed_host(url) || scp_like_host(url) || (url) end |
.normalize_host(host) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 41 42 43 44 45 46 |
# File 'lib/spm_version_updates/git_host_normalizer.rb', line 38 def normalize_host(host) normalized = normalized_ipv6_host(host) return normalized if normalized normalized = host.to_s.sub(/:\d+\z/, "").downcase return normalized if normalized.match?(HOST_PATTERN) nil end |
.normalize_ipv6_address(address) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 60 61 62 |
# File 'lib/spm_version_updates/git_host_normalizer.rb', line 57 def normalize_ipv6_address(address) parsed = IPAddr.new(address) parsed.ipv6? ? parsed.to_s : nil rescue IPAddr::Error nil end |
.normalized_ipv6_host(host) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 51 52 53 54 55 |
# File 'lib/spm_version_updates/git_host_normalizer.rb', line 48 def normalized_ipv6_host(host) raw = host.to_s.strip.downcase bracketed = raw.match(BRACKETED_IPV6_PATTERN) return normalize_ipv6_address(bracketed[:address]) if bracketed return normalize_ipv6_address(raw) if raw.count(":") >= 2 nil end |
.parsed_host(url) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 23 24 |
# File 'lib/spm_version_updates/git_host_normalizer.rb', line 20 def parsed_host(url) normalize_host(URI.parse(url).host) rescue URI::InvalidURIError nil end |
.scp_like_host(url) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 29 |
# File 'lib/spm_version_updates/git_host_normalizer.rb', line 26 def scp_like_host(url) match = url.match(%r{\A(?:[^@\s/]+@)?(?<host>[^:\s/]+):(?!/)[^:\s]+\z}) match && normalize_host(match[:host]) end |