Class: WebValve::ServiceUrlConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/webvalve/service_url_converter.rb

Constant Summary collapse

TOKEN_BOUNDARY_CHARS =
Regexp.escape('.:/?#@&=').freeze
WILDCARD_SUBSTITUTION =
('[^' + TOKEN_BOUNDARY_CHARS + ']*').freeze
URL_PREFIX_BOUNDARY =
('[' + TOKEN_BOUNDARY_CHARS + ']').freeze
URL_SUFFIX_PATTERN =
('((' + URL_PREFIX_BOUNDARY + '|(?<=' + URL_PREFIX_BOUNDARY + ')).*)?\z').freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:) ⇒ ServiceUrlConverter

Returns a new instance of ServiceUrlConverter.



10
11
12
# File 'lib/webvalve/service_url_converter.rb', line 10

def initialize(url:)
  @url = url
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/webvalve/service_url_converter.rb', line 8

def url
  @url
end

Instance Method Details

#regexpObject



14
15
16
17
18
19
20
21
22
# File 'lib/webvalve/service_url_converter.rb', line 14

def regexp
  if url.is_a?(String)
    regexp_string = Regexp.escape(url)
    substituted_regexp_string = regexp_string.gsub('\*', WILDCARD_SUBSTITUTION)
    %r(\A#{substituted_regexp_string}#{URL_SUFFIX_PATTERN})
  else
    url
  end
end