Class: SiteHub::LocationRewriter
- Inherits:
-
Object
- Object
- SiteHub::LocationRewriter
- Includes:
- Equality
- Defined in:
- lib/sitehub/location_rewriter.rb
Instance Attribute Summary collapse
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#path_template ⇒ Object
readonly
Returns the value of attribute path_template.
Instance Method Summary collapse
- #apply(downstream_url, source_url) ⇒ Object
-
#initialize(matcher, path_template) ⇒ LocationRewriter
constructor
A new instance of LocationRewriter.
- #match?(url) ⇒ Boolean
Methods included from Equality
Constructor Details
#initialize(matcher, path_template) ⇒ LocationRewriter
Returns a new instance of LocationRewriter.
8 9 10 11 |
# File 'lib/sitehub/location_rewriter.rb', line 8 def initialize(matcher, path_template) @matcher = matcher @path_template = path_template end |
Instance Attribute Details
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
6 7 8 |
# File 'lib/sitehub/location_rewriter.rb', line 6 def matcher @matcher end |
#path_template ⇒ Object (readonly)
Returns the value of attribute path_template.
6 7 8 |
# File 'lib/sitehub/location_rewriter.rb', line 6 def path_template @path_template end |
Instance Method Details
#apply(downstream_url, source_url) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# 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) ⇒ Boolean
13 14 15 |
# File 'lib/sitehub/location_rewriter.rb', line 13 def match?(url) matcher.match(url).is_a?(MatchData) end |