diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2010-03-26 12:16:25 +0000 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-03-27 00:21:10 -0700 |
commit | 3d746fcdb584767c476408f395320e934fd5383e (patch) | |
tree | 29b5426da20d7840d717effe405077d085ad59e6 /actionpack/lib | |
parent | b20a105ed0d52bf1490cf0fad97e0b3268ba63fd (diff) | |
download | rails-3d746fcdb584767c476408f395320e934fd5383e.tar.gz rails-3d746fcdb584767c476408f395320e934fd5383e.tar.bz2 rails-3d746fcdb584767c476408f395320e934fd5383e.zip |
Add parameter defaults support to new routing DSL [#4265 state:resolved]
Signed-off-by: wycats <wycats@gmail.com>
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 278cf383ee..cc3ed169d8 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -32,6 +32,8 @@ module ActionDispatch end class Mapping + IGNORE_OPTIONS = [:to, :as, :controller, :action, :via, :on, :constraints, :defaults, :only, :except, :anchor] + def initialize(set, scope, args) @set, @scope = set, scope @path, @options = extract_path_and_options(args) @@ -96,7 +98,15 @@ module ActionDispatch end def defaults - @defaults ||= if to.respond_to?(:call) + @defaults ||= (@options[:defaults] || {}).tap do |defaults| + defaults.merge!(default_controller_and_action) + defaults.reverse_merge!(@scope[:defaults]) if @scope[:defaults] + @options.each { |k, v| defaults[k] = v unless v.is_a?(Regexp) || IGNORE_OPTIONS.include?(k.to_sym) } + end + end + + def default_controller_and_action + if to.respond_to?(:call) { } else defaults = case to @@ -299,6 +309,10 @@ module ActionDispatch scope(:constraints => constraints) { yield } end + def defaults(defaults = {}) + scope(:defaults => defaults) { yield } + end + def match(*args) options = args.extract_options! @@ -343,6 +357,10 @@ module ActionDispatch merge_options_scope(parent, child) end + def merge_defaults_scope(parent, child) + merge_options_scope(parent, child) + end + def merge_blocks_scope(parent, child) (parent || []) + [child] end |