diff options
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/routing.rb | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 008e6d2164..f7d3fe3369 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -26,15 +26,19 @@ module ActionController end hash end - end - - class << self + def test_condition(expression, condition) case condition when String then "(#{expression} == #{condition.inspect})" when Regexp then condition = Regexp.new("^#{condition.source}$") unless /^\^.*\$$/ =~ condition.source "(#{condition.inspect} =~ #{expression})" + when Array then + conds = condition.collect do |condition| + cond = test_condition(expression, condition) + (cond[0, 1] == '(' && cond[-1, 1] == ')') ? cond : "(#{cond})" + end + "(#{conds.join(' || ')})" when true then expression when nil then "! #{expression}" else @@ -272,6 +276,7 @@ module ActionController defaults, conditions = initialize_hashes options.dup @defaults = defaults.dup configure_components(defaults, conditions) + add_default_requirements initialize_keys end @@ -324,7 +329,6 @@ module ActionController end protected - def initialize_components(path) path = path.split('/') if path.is_a? String path.shift if path.first.blank? @@ -356,6 +360,11 @@ module ActionController component.condition = conditions[component.key] if conditions.key?(component.key) end end + + def add_default_requirements + component_keys = components.collect {|c| c.key} + known[:action] ||= [nil, 'index'] unless component_keys.include? :action + end end class RouteSet #:nodoc: |