aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/mapper.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-08-14 09:13:51 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-08-14 10:39:32 -0700
commit1eb6b4a679b05e443792430f11f084746005f6ff (patch)
treee988fa8025d7cf9606ed97cf54a6ff26d7a3d078 /actionpack/lib/action_dispatch/routing/mapper.rb
parent9a4a436fd7519acce3a1b857a7636bc157384646 (diff)
downloadrails-1eb6b4a679b05e443792430f11f084746005f6ff.tar.gz
rails-1eb6b4a679b05e443792430f11f084746005f6ff.tar.bz2
rails-1eb6b4a679b05e443792430f11f084746005f6ff.zip
pull up path normalization.
Eventually I want to pull up AST generation so that we don't have to add it to the `conditions` hash.
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb36
1 files changed, 18 insertions, 18 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 09eb1559f1..8a90c40d2b 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -82,6 +82,22 @@ module ActionDispatch
via
end
+ def self.normalize_path(path, format)
+ path = Mapper.normalize_path(path)
+
+ if format == true
+ "#{path}.:format"
+ elsif optional_format?(path, format)
+ "#{path}(.:format)"
+ else
+ path
+ end
+ end
+
+ def self.optional_format?(path, format)
+ format != false && !path.include?(':format') && !path.end_with?('/')
+ end
+
def initialize(set, path, defaults, controller, default_action, modyoule, to, formatted, scope_constraints, blocks, via, options_constraints, options)
@defaults = defaults
@set = set
@@ -90,7 +106,6 @@ module ActionDispatch
@default_controller = controller
@default_action = default_action
- path = normalize_path! path, formatted
ast = path_ast path
path_params = path_params ast
@@ -133,22 +148,6 @@ module ActionDispatch
private
- def normalize_path!(path, format)
- path = Mapper.normalize_path(path)
-
- if format == true
- "#{path}.:format"
- elsif optional_format?(path, format)
- "#{path}(.:format)"
- else
- path
- end
- end
-
- def optional_format?(path, format)
- format != false && !path.include?(':format') && !path.end_with?('/')
- end
-
def normalize_options!(options, formatted, path_params, path_ast, modyoule)
# Add a constraint for wildcard route to make it non-greedy and match the
# optional format part of the route by default
@@ -1608,7 +1607,8 @@ module ActionDispatch
name_for_action(options.delete(:as), action)
end
- mapping = Mapping.build(@scope, @set, URI.parser.escape(path), controller, default_action, to, via, formatted, options_constraints, options)
+ path = Mapping.normalize_path URI.parser.escape(path), formatted
+ mapping = Mapping.build(@scope, @set, path, controller, default_action, to, via, formatted, options_constraints, options)
app, conditions, requirements, defaults = mapping.to_route
@set.add_route(app, conditions, requirements, defaults, as, anchor)
end