Module: Pretzel::Routing::Evaluation::ClassMethods
- Defined in:
- lib/pretzel/routing/eval.rb
Overview
For all regex lovers.
Instance Method Summary collapse
Instance Method Details
#compile_route(pattern) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pretzel/routing/eval.rb', line 11 def compile_route(pattern) keys = [] pattern = pattern[0...-1] if pattern.end_with?("/") pattern.gsub!(/(:\w+)/) do # Get all colon-prefixed params keys << $1[1..-1] # Put the name of them into the keys array. "([^/?#]+)" # Substitute with a capture group. end # Return the regex and the param names. if pattern != "/" # No trailing slash for the root route. [%r{^#{pattern}\/?$}, keys] else [%r{^#{pattern}$}, keys] end end |