class SiteHub::LocationRewriter

Attributes

matcher[R]
path_template[R]

Public Class Methods

new(matcher, path_template) click to toggle source
# File lib/sitehub/location_rewriter.rb, line 8
def initialize(matcher, path_template)
  @matcher = matcher
  @path_template = path_template
end

Public Instance Methods

apply(downstream_url, source_url) click to toggle source
# File lib/sitehub/location_rewriter.rb, line 17
def apply(downstream_url, source_url)
  url_components = matcher.match(downstream_url).captures

  path = path_template.dup.tap do |template|
    url_components.each.with_index(1) do |component, index|
      template.gsub!(RequestMapping::CAPTURE_GROUP_REFERENCE % index, component)
    end
  end

  "#{source_url[RequestMapping::BASE_URL_MATCHER]}#{path}"
end
match?(url) click to toggle source
# File lib/sitehub/location_rewriter.rb, line 13
def match?(url)
  matcher.match(url).is_a?(MatchData)
end