class Openapi3Parser::SourceInput::Url::RelativeUrlDifference

Attributes

from_uri[R]
to_uri[R]

Public Class Methods

call(from_url, to_url) click to toggle source
# File lib/openapi3_parser/source_input/url.rb, line 87
def self.call(from_url, to_url)
  new(from_url, to_url).call
end

Private Class Methods

new(from_url, to_url) click to toggle source
# File lib/openapi3_parser/source_input/url.rb, line 82
def initialize(from_url, to_url)
  @from_uri = URI.parse(from_url)
  @to_uri = URI.parse(to_url)
end

Public Instance Methods

call() click to toggle source
# File lib/openapi3_parser/source_input/url.rb, line 91
def call
  return to_uri.to_s if different_hosts?

  relative_path
end

Private Instance Methods

different_hosts?() click to toggle source
# File lib/openapi3_parser/source_input/url.rb, line 103
def different_hosts?
  URI.join(from_uri, "/") != URI.join(to_uri, "/")
end
file_and_query(uri) click to toggle source
# File lib/openapi3_parser/source_input/url.rb, line 115
def file_and_query(uri)
  Pathname.new(uri.path).basename.to_s +
    (uri.query ? "?#{uri.query}" : "")
end
relative_path() click to toggle source
# File lib/openapi3_parser/source_input/url.rb, line 107
def relative_path
  relative = to_uri.route_from(from_uri)
  return relative.to_s unless relative.path.empty?

  # if we have same path it's nice to show just the filename
  file_and_query(to_uri)
end