class SiteHub::RequestMapping

Constants

BASE_URL_MATCHER
CAPTURE_GROUP_REFERENCE
USER_SUPPLIED_CAPTURE

Attributes

mapped_path[R]
mapped_url[R]
source_url[R]

Public Class Methods

new(source_url:, mapped_url: EMPTY_STRING, mapped_path:) click to toggle source
# File lib/sitehub/request_mapping.rb, line 14
def initialize(source_url:, mapped_url: EMPTY_STRING, mapped_path:)
  @source_url = source_url
  @mapped_url = mapped_url.to_s.dup
  mapped_path = mapped_path.to_s.dup
  @mapped_path = mapped_path.is_a?(Regexp) ? mapped_path : Regexp.new(mapped_path)
end

Public Instance Methods

computed_uri() click to toggle source
# File lib/sitehub/request_mapping.rb, line 21
def computed_uri
  url_components = url_scanner_regex.match(source_url).captures[USER_SUPPLIED_CAPTURE]
  mapped_url.tap do |url|
    url_components.each_with_index do |match, index|
      url.gsub!(CAPTURE_GROUP_REFERENCE % (index + 1), match)
    end
  end
  URI(mapped_url)
end
host() click to toggle source
# File lib/sitehub/request_mapping.rb, line 32
def host
  URI(source_url).host
end

Private Instance Methods

url_scanner_regex() click to toggle source
# File lib/sitehub/request_mapping.rb, line 39
def url_scanner_regex
  /#{BASE_URL_MATCHER.source}#{mapped_path.source}/
end