aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/http/headers.rb14
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb6
-rw-r--r--actionpack/lib/action_dispatch/middleware/stack.rb5
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb16
4 files changed, 28 insertions, 13 deletions
diff --git a/actionpack/lib/action_dispatch/http/headers.rb b/actionpack/lib/action_dispatch/http/headers.rb
index 2a41b4dbad..1e43104f0a 100644
--- a/actionpack/lib/action_dispatch/http/headers.rb
+++ b/actionpack/lib/action_dispatch/http/headers.rb
@@ -6,13 +6,13 @@ module ActionDispatch
extend ActiveSupport::Memoizable
def initialize(*args)
- if args.size == 1 && args[0].is_a?(Hash)
- super()
- update(args[0])
- else
- super
- end
- end
+ if args.size == 1 && args[0].is_a?(Hash)
+ super()
+ update(args[0])
+ else
+ super
+ end
+ end
def [](header_name)
if include?(header_name)
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb
index c30897b32a..13c0f2bad0 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -10,8 +10,8 @@ module Mime
%w(<< concat shift unshift push pop []= clear compact! collect!
delete delete_at delete_if flatten! map! insert reject! reverse!
replace slice! sort! uniq!).each do |method|
- module_eval <<-CODE
- def #{method}(*args)
+ module_eval <<-CODE, __FILE__, __LINE__ + 1
+ def #{method}(*)
@symbols = nil
super
end
@@ -104,7 +104,7 @@ module Mime
SET << Mime.const_get(symbol.to_s.upcase)
- ([string] + mime_type_synonyms).each { |string| LOOKUP[string] = SET.last } unless skip_lookup
+ ([string] + mime_type_synonyms).each { |str| LOOKUP[str] = SET.last } unless skip_lookup
([symbol.to_s] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext] = SET.last }
end
diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb
index 3b27309f58..24be4fee55 100644
--- a/actionpack/lib/action_dispatch/middleware/stack.rb
+++ b/actionpack/lib/action_dispatch/middleware/stack.rb
@@ -93,8 +93,9 @@ module ActionDispatch
alias_method :insert_before, :insert
def insert_after(index, *args, &block)
- index = self.index(index) unless index.is_a?(Integer)
- insert(index + 1, *args, &block)
+ i = index.is_a?(Integer) ? index : self.index(index)
+ raise "No such middleware to insert after: #{index.inspect}" unless i
+ insert(i + 1, *args, &block)
end
def swap(target, *args, &block)
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index e655d6a708..8f33346a4f 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -43,9 +43,13 @@ module ActionDispatch
def extract_path_and_options(args)
options = args.extract_options!
- if args.empty?
+ case
+ when using_to_shorthand?(args, options)
path, to = options.find { |name, value| name.is_a?(String) }
options.merge!(:to => to).delete(path) if path
+ when using_match_shorthand?(args, options)
+ path = args.first
+ options = { :to => path.gsub("/", "#"), :as => path.gsub("/", "_") }
else
path = args.first
end
@@ -53,6 +57,16 @@ module ActionDispatch
[ normalize_path(path), options ]
end
+ # match "account" => "account#index"
+ def using_to_shorthand?(args, options)
+ args.empty? && options.present?
+ end
+
+ # match "account/overview"
+ def using_match_shorthand?(args, options)
+ args.present? && options.except(:via).empty? && !args.first.include?(':')
+ end
+
def normalize_path(path)
path = nil if path == ""
path = "#{@scope[:path]}#{path}" if @scope[:path]