Class: MailGrabber::Web::ApplicationRouter::Route
- Inherits:
-
Struct
- Object
- Struct
- MailGrabber::Web::ApplicationRouter::Route
- Defined in:
- lib/mail_grabber/web/application_router.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#extract_params(path) ⇒ Hash/NilClass
Extract parameters from the given path.
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block
10 11 12 |
# File 'lib/mail_grabber/web/application_router.rb', line 10 def block @block end |
#pattern ⇒ Object
Returns the value of attribute pattern
10 11 12 |
# File 'lib/mail_grabber/web/application_router.rb', line 10 def pattern @pattern end |
Instance Method Details
#extract_params(path) ⇒ Hash/NilClass
Extract parameters from the given path. All routes have a path pattern which helps to the router to find which block it should execute. If the path contains request parameters like ‘/test/1’ then it will match with the ‘/test/:id’ pattern. In this case, it will return with ‘=> “1”’ hash. If it is just a simple path like ‘/’ and it has a pattern to match, then it will return with ‘{}’. In the other case, it will return with nil.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mail_grabber/web/application_router.rb', line 24 def extract_params(path) if pattern.match?(NAMED_SEGMENTS_PATTERN) named_pattern = pattern.gsub(NAMED_SEGMENTS_PATTERN, '/\1(?<\2>[^$/]+)') path.match(Regexp.new("\\A#{named_pattern}\\Z"))&.named_captures elsif path == pattern {} end end |