Class: JSON::Util::URI Private

Inherits:
Addressable::URI
  • Object
show all
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

Instance Method Summary collapse

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.

Parameters:

  • uri (String, Addressable::URI)

Returns:

  • (Addressable::URI, nil)


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

Parameters:

  • ref (String, Addressable::URI)
  • base (String, Addressable::URI)

Returns:

  • (Addressable::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.

Parameters:

  • uri (String, Addressable::URI)

Returns:

  • (Addressable::URI)


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.

Parameters:

  • uri (String, Addressable::URI)

Returns:

  • (Addressable::URI, nil)


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.message
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.

Parameters:

  • uri (String, Addressable::URI)

Returns:

  • (Addressable::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.

Parameters:

  • uri (String, Addressable::URI)

    ri [String, Addressable::URI

Returns:

  • (String)


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.

Parameters:

  • base (Addressable::URI, String)

Returns:

  • (Addressable::URI)


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.

Parameters:

  • base (Addressable::URI, String)

Returns:

  • (Addressable::URI)


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.

Parameters:

  • base_path (String) (defaults to: Dir.pwd)

    the base path to use for relative URIs. Defaults to the current working directory.

Returns:

  • (Addressable::URI)

    the normalized URI or nil



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_fragmentAddressable::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.

Returns:

  • (Addressable::URI)

    a new instance of URI without a fragment



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_pathString

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.

Returns:

  • (String)


64
65
66
# File 'lib/json-schema/util/uri.rb', line 64

def unescaped_path
  self.class.unescape_component(path)
end