diff options
author | Gibheer <gibheer@gmail.com> | 2013-02-11 19:51:54 +0100 |
---|---|---|
committer | Gibheer <gibheer@gmail.com> | 2013-02-11 19:51:54 +0100 |
commit | 8ff98ff9dd6fef4007f5be9d79d68368509094fd (patch) | |
tree | a2dc30324fa9e3972569b7baba0cdff6407f31d5 | |
parent | 1133c4106ffb92418866de9f917ce4687164e63b (diff) |
change route regex to string beginning and end
-rw-r--r-- | lib/zero/router.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/zero/router.rb b/lib/zero/router.rb index e5b513c..659d9b6 100644 --- a/lib/zero/router.rb +++ b/lib/zero/router.rb @@ -21,6 +21,10 @@ module Zero VARIABLE_MATCH = %r{:(\w+)[^/]?} # the replacement string to make it an regex VARIABLE_REGEX = '(?<\1>.+?)' + # regex part of the beginning of the line + REGEX_BEGINNING = '\A' + # regex part of the end of the line + REGEX_END = '\Z' # environment key to store custom parameters ENV_KEY_CUSTOM = 'zero.params.custom' # environment key to the path info @@ -39,8 +43,9 @@ module Zero @routes = {} routes.each do |route, target| @routes[ - Regexp.new( - '^' + route.gsub(VARIABLE_MATCH, VARIABLE_REGEX) + '$')] = target + Regexp.new(REGEX_BEGINNING + + route.gsub(VARIABLE_MATCH, VARIABLE_REGEX) + + REGEX_END)] = target end end |