Class: Sidekiq::WebRoute
- Inherits:
-
Object
- Object
- Sidekiq::WebRoute
- Defined in:
- lib/sidekiq/web/router.rb
Constant Summary collapse
- NAMED_SEGMENTS_PATTERN =
/\/([^\/]*):([^\.:$\/]+)/
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) ⇒ WebRoute
constructor
A new instance of WebRoute.
- #match(request_method, path) ⇒ Object
- #matcher ⇒ Object
Constructor Details
#initialize(request_method, pattern, block) ⇒ WebRoute
Returns a new instance of WebRoute.
71 72 73 74 75 |
# File 'lib/sidekiq/web/router.rb', line 71 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.
67 68 69 |
# File 'lib/sidekiq/web/router.rb', line 67 def block @block end |
#name ⇒ Object
Returns the value of attribute name.
67 68 69 |
# File 'lib/sidekiq/web/router.rb', line 67 def name @name end |
#pattern ⇒ Object
Returns the value of attribute pattern.
67 68 69 |
# File 'lib/sidekiq/web/router.rb', line 67 def pattern @pattern end |
#request_method ⇒ Object
Returns the value of attribute request_method.
67 68 69 |
# File 'lib/sidekiq/web/router.rb', line 67 def request_method @request_method end |
Instance Method Details
#compile ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/sidekiq/web/router.rb', line 81 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
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/sidekiq/web/router.rb', line 91 def match(request_method, path) case matcher when String {} if path == matcher else path_match = path.match(matcher) if path_match Hash[path_match.names.map(&:to_sym).zip(path_match.captures)] end end end |
#matcher ⇒ Object
77 78 79 |
# File 'lib/sidekiq/web/router.rb', line 77 def matcher @matcher ||= compile end |