Class: JSON::Util::URI Private
- Inherits:
-
Addressable::URI
- Object
- Addressable::URI
- JSON::Util::URI
- Defined in:
- lib/json-schema/util/uri.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- SUPPORTED_PROTOCOLS =
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.
%w(http https ftp tftp sftp ssh svn+ssh telnet nntp gopher wais ldap prospero)
Class Method Summary collapse
- .absolutize_ref(ref, base) ⇒ Object private
- .file_uri(uri) ⇒ Addressable::URI? private
-
.normalize_ref(ref, base) ⇒ Addressable::URI
private
Normalizes the reference URI based on the provided base URI.
- .normalized_uri(uri, base_path = Dir.pwd) ⇒ Addressable::URI private
- .parse(uri) ⇒ Addressable::URI? private
-
.strip_fragment(uri) ⇒ Addressable::URI
private
Strips the fragment from the URI.
- .unescaped_path(uri) ⇒ String private
Instance Method Summary collapse
- #absolutize_ref(base) ⇒ Addressable::URI private
- #normalize_ref(base) ⇒ Addressable::URI private
-
#normalized_uri(base_path = Dir.pwd) ⇒ Addressable::URI
private
Normalizes the URI based on the provided base path.
-
#strip_fragment ⇒ Addressable::URI
private
Strips the fragment from the URI.
-
#unescaped_path ⇒ String
private
Unencodes any percent encoded characters within a path component.
Class Method Details
.absolutize_ref(ref, base) ⇒ 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.
56 57 58 |
# File 'lib/json-schema/util/uri.rb', line 56 def absolutize_ref(ref, base) parse(ref).absolutize_ref(base) end |
.file_uri(uri) ⇒ Addressable::URI?
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.
24 25 26 |
# File 'lib/json-schema/util/uri.rb', line 24 def file_uri(uri) convert_path(parse(uri).path) end |
.normalize_ref(ref, base) ⇒ Addressable::URI
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.
Normalizes the reference URI based on the provided base URI
52 53 54 |
# File 'lib/json-schema/util/uri.rb', line 52 def normalize_ref(ref, base) parse(ref).normalize_ref(base) end |
.normalized_uri(uri, base_path = Dir.pwd) ⇒ Addressable::URI
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.
43 44 45 |
# File 'lib/json-schema/util/uri.rb', line 43 def normalized_uri(uri, base_path = Dir.pwd) parse(uri).normalized_uri(base_path) end |
.parse(uri) ⇒ Addressable::URI?
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.
16 17 18 19 20 |
# File 'lib/json-schema/util/uri.rb', line 16 def parse(uri) super(uri) rescue Addressable::URI::InvalidURIError => e raise JSON::Schema::UriError, e. end |
.strip_fragment(uri) ⇒ Addressable::URI
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.
Strips the fragment from the URI.
37 38 39 |
# File 'lib/json-schema/util/uri.rb', line 37 def strip_fragment(uri) parse(uri).strip_fragment end |
.unescaped_path(uri) ⇒ String
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.
30 31 32 |
# File 'lib/json-schema/util/uri.rb', line 30 def unescaped_path(uri) parse(uri).unescaped_path end |
Instance Method Details
#absolutize_ref(base) ⇒ Addressable::URI
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.
123 124 125 126 127 128 129 130 |
# File 'lib/json-schema/util/uri.rb', line 123 def absolutize_ref(base) ref = strip_fragment if ref.absolute? ref else self.class.strip_fragment(base).join(ref.path).normalized_uri end end |
#normalize_ref(base) ⇒ Addressable::URI
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.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/json-schema/util/uri.rb', line 96 def normalize_ref(base) base_uri = self.class.parse(base) defer_validation do if relative? # Check for absolute path path, fragment = to_s.split('#') merge!(base_uri) if path.nil? || path == '' self.path = base_uri.path elsif path[0, 1] == '/' self.path = Pathname.new(path).cleanpath.to_s else join!(path) end self.fragment = fragment end self.fragment = '' if self.fragment.nil? || self.fragment.empty? end self end |
#normalized_uri(base_path = Dir.pwd) ⇒ Addressable::URI
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.
Normalizes the URI based on the provided base path.
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/json-schema/util/uri.rb', line 82 def normalized_uri(base_path = Dir.pwd) if relative? if path[0, 1] == '/' self.class.file_uri(self) else self.class.file_uri(File.join(base_path, self)) end else self end end |
#strip_fragment ⇒ Addressable::URI
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.
Strips the fragment from the URI.
70 71 72 73 74 75 76 |
# File 'lib/json-schema/util/uri.rb', line 70 def strip_fragment if fragment.nil? || fragment.empty? self else merge(fragment: '') end end |
#unescaped_path ⇒ String
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.
Unencodes any percent encoded characters within a path component.
64 65 66 |
# File 'lib/json-schema/util/uri.rb', line 64 def unescaped_path self.class.unescape_component(path) end |