Class: Openapi3Parser::SourceInput::Url

Inherits:
Openapi3Parser::SourceInput show all
Defined in:
lib/openapi3_parser/source_input/url.rb

Overview

An input of a URL to an OpenAPI file

Defined Under Namespace

Classes: RelativeUrlDifference

Instance Attribute Summary collapse

Attributes inherited from Openapi3Parser::SourceInput

#access_error, #parse_error

Instance Method Summary collapse

Methods inherited from Openapi3Parser::SourceInput

#available?, #contents

Constructor Details

#initialize(request_url) ⇒ Url

Returns a new instance of Url.

Parameters:

  • request_url (String, URI)

18
19
20
21
# File 'lib/openapi3_parser/source_input/url.rb', line 18

def initialize(request_url)
  @request_url = request_url.to_s
  super()
end

Instance Attribute Details

#request_urlString (readonly)

The URL that will be requested

Returns:

  • (String)

    the current value of request_url


14
15
16
# File 'lib/openapi3_parser/source_input/url.rb', line 14

def request_url
  @request_url
end

#resolved_urlString (readonly)

The eventual URL of the file that was accessed, this may differ to the request_url in the case of redirects

Returns:

  • (String)

    the current value of resolved_url


14
15
16
# File 'lib/openapi3_parser/source_input/url.rb', line 14

def resolved_url
  @resolved_url
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)

See Also:

  • SourceInput#other

33
34
35
36
37
38
# File 'lib/openapi3_parser/source_input/url.rb', line 33

def ==(other)
  return false unless other.instance_of?(self.class)

  [request_url, resolved_url].include?(other.request_url) ||
    [request_url, resolved_url].include?(other.resolved_url)
end

#inspectObject

return [String]


46
47
48
# File 'lib/openapi3_parser/source_input/url.rb', line 46

def inspect
  %{#{self.class.name}(url: #{url})}
end

#relative_to(source_input) ⇒ String

Returns:

  • (String)

56
57
58
59
60
61
62
63
64
65
66
# File 'lib/openapi3_parser/source_input/url.rb', line 56

def relative_to(source_input)
  other_url = if source_input.respond_to?(:url)
                source_input.url
              elsif source_input.respond_to?(:base_url)
                source_input.base_url
              end

  return url unless other_url

  other_url ? RelativeUrlDifference.call(other_url, url) : url
end

#resolve_next(reference) ⇒ SourceInput

Parameters:

Returns:

See Also:


26
27
28
# File 'lib/openapi3_parser/source_input/url.rb', line 26

def resolve_next(reference)
  ResolveNext.call(reference, self, base_url: resolved_url)
end

#to_sString

Returns:

  • (String)

51
52
53
# File 'lib/openapi3_parser/source_input/url.rb', line 51

def to_s
  request_url
end

#urlObject

return [String]


41
42
43
# File 'lib/openapi3_parser/source_input/url.rb', line 41

def url
  resolved_url || request_url
end