Class: Sidekiq::Web::Route
- Inherits:
-
Object
- Object
- Sidekiq::Web::Route
- Defined in:
- lib/sidekiq/web/router.rb
Constant Summary collapse
- NAMED_SEGMENTS_PATTERN =
/\/([^\/]*):([^.:$\/]+)/
- EMPTY =
{}.freeze
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#request_method ⇒ Object
Returns the value of attribute request_method.
Instance Method Summary collapse
- #compile ⇒ Object
-
#initialize(request_method, pattern, block) ⇒ Route
constructor
A new instance of Route.
- #match(request_method, path) ⇒ Object
- #matcher ⇒ Object
Constructor Details
#initialize(request_method, pattern, block) ⇒ Route
Returns a new instance of Route.
58 59 60 61 62 |
# File 'lib/sidekiq/web/router.rb', line 58 def initialize(request_method, pattern, block) @request_method = request_method @pattern = pattern @block = block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
54 55 56 |
# File 'lib/sidekiq/web/router.rb', line 54 def block @block end |
#name ⇒ Object
Returns the value of attribute name.
54 55 56 |
# File 'lib/sidekiq/web/router.rb', line 54 def name @name end |
#pattern ⇒ Object
Returns the value of attribute pattern.
54 55 56 |
# File 'lib/sidekiq/web/router.rb', line 54 def pattern @pattern end |
#request_method ⇒ Object
Returns the value of attribute request_method.
54 55 56 |
# File 'lib/sidekiq/web/router.rb', line 54 def request_method @request_method end |
Instance Method Details
#compile ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/sidekiq/web/router.rb', line 68 def compile if pattern.match?(NAMED_SEGMENTS_PATTERN) p = pattern.gsub(NAMED_SEGMENTS_PATTERN, '/\1(?<\2>[^$/]+)') Regexp.new("\\A#{p}\\Z") else pattern end end |
#match(request_method, path) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/sidekiq/web/router.rb', line 80 def match(request_method, path) case matcher when String EMPTY if path == matcher else path_match = path.match(matcher) path_match&.named_captures&.transform_keys(&:to_sym) end end |
#matcher ⇒ Object
64 65 66 |
# File 'lib/sidekiq/web/router.rb', line 64 def matcher @matcher ||= compile end |