diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-11-14 17:41:25 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-11-14 17:41:25 +0530 |
commit | 17b1387646a9537c978e9d7c5f3a68f740cd9377 (patch) | |
tree | 81735b97603471bb9780ed0fd133dad7a16f59a7 /actionpack/lib/action_controller/routing/builder.rb | |
parent | fa9ea057d1252a578f8e056defef41b93853bc8b (diff) | |
parent | 549b18c9286b6cccf4978093576325fd711dc421 (diff) | |
download | rails-17b1387646a9537c978e9d7c5f3a68f740cd9377.tar.gz rails-17b1387646a9537c978e9d7c5f3a68f740cd9377.tar.bz2 rails-17b1387646a9537c978e9d7c5f3a68f740cd9377.zip |
Merge commit 'mainstream/master'
Conflicts:
railties/doc/guides/html/actioncontroller_basics.html
railties/doc/guides/html/activerecord_validations_callbacks.html
railties/doc/guides/html/debugging_rails_applications.html
railties/doc/guides/html/testing_rails_applications.html
railties/doc/guides/source/actioncontroller_basics/methods.txt
railties/doc/guides/source/actioncontroller_basics/params.txt
railties/doc/guides/source/actioncontroller_basics/request_response_objects.txt
railties/doc/guides/source/actioncontroller_basics/session.txt
railties/doc/guides/source/activerecord_validations_callbacks.txt
railties/doc/guides/source/debugging_rails_applications.txt
railties/doc/guides/source/testing_rails_applications.txt
Diffstat (limited to 'actionpack/lib/action_controller/routing/builder.rb')
-rw-r--r-- | actionpack/lib/action_controller/routing/builder.rb | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/actionpack/lib/action_controller/routing/builder.rb b/actionpack/lib/action_controller/routing/builder.rb index 7b888fa8d2..d4e501e780 100644 --- a/actionpack/lib/action_controller/routing/builder.rb +++ b/actionpack/lib/action_controller/routing/builder.rb @@ -1,23 +1,16 @@ module ActionController module Routing class RouteBuilder #:nodoc: - attr_accessor :separators, :optional_separators + attr_reader :separators, :optional_separators + attr_reader :separator_regexp, :nonseparator_regexp, :interval_regexp def initialize - self.separators = Routing::SEPARATORS - self.optional_separators = %w( / ) - end - - def separator_pattern(inverted = false) - "[#{'^' if inverted}#{Regexp.escape(separators.join)}]" - end - - def interval_regexp - Regexp.new "(.*?)(#{separators.source}|$)" - end + @separators = Routing::SEPARATORS + @optional_separators = %w( / ) - def multiline_regexp?(expression) - expression.options & Regexp::MULTILINE == Regexp::MULTILINE + @separator_regexp = /[#{Regexp.escape(separators.join)}]/ + @nonseparator_regexp = /\A([^#{Regexp.escape(separators.join)}]+)/ + @interval_regexp = /(.*?)(#{separator_regexp}|$)/ end # Accepts a "route path" (a string defining a route), and returns the array @@ -30,7 +23,7 @@ module ActionController rest, segments = path, [] until rest.empty? - segment, rest = segment_for rest + segment, rest = segment_for(rest) segments << segment end segments @@ -39,20 +32,20 @@ module ActionController # A factory method that returns a new segment instance appropriate for the # format of the given string. def segment_for(string) - segment = case string - when /\A:(\w+)/ - key = $1.to_sym - case key - when :controller then ControllerSegment.new(key) - else DynamicSegment.new key - end - when /\A\*(\w+)/ then PathSegment.new($1.to_sym, :optional => true) - when /\A\?(.*?)\?/ - StaticSegment.new($1, :optional => true) - when /\A(#{separator_pattern(:inverted)}+)/ then StaticSegment.new($1) - when Regexp.new(separator_pattern) then - DividerSegment.new($&, :optional => (optional_separators.include? $&)) - end + segment = + case string + when /\A:(\w+)/ + key = $1.to_sym + key == :controller ? ControllerSegment.new(key) : DynamicSegment.new(key) + when /\A\*(\w+)/ + PathSegment.new($1.to_sym, :optional => true) + when /\A\?(.*?)\?/ + StaticSegment.new($1, :optional => true) + when nonseparator_regexp + StaticSegment.new($1) + when separator_regexp + DividerSegment.new($&, :optional => optional_separators.include?($&)) + end [segment, $~.post_match] end @@ -98,7 +91,7 @@ module ActionController if requirement.source =~ %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z} raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}" end - if multiline_regexp?(requirement) + if requirement.multiline? raise ArgumentError, "Regexp multiline option not allowed in routing requirements: #{requirement.inspect}" end segment.regexp = requirement |