aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-06-22 23:23:18 +0200
committerJosé Valim <jose.valim@gmail.com>2010-06-22 23:30:19 +0200
commitfef5cf92ed883daf663299258549bc7aa454db1e (patch)
tree81e5cea7dc5641920d10c8880b7c1a2cbaaaeeea /actionpack
parent62c4e4d3856b38ee9869f4ad6342e712788c8635 (diff)
downloadrails-fef5cf92ed883daf663299258549bc7aa454db1e.tar.gz
rails-fef5cf92ed883daf663299258549bc7aa454db1e.tar.bz2
rails-fef5cf92ed883daf663299258549bc7aa454db1e.zip
Deprecate :name_prefix in the new router DSL.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb42
-rw-r--r--actionpack/test/dispatch/routing_test.rb6
3 files changed, 27 insertions, 23 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index a00f63dcd4..2b3e6a5714 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*Rails 3.0.0 [Release Candidate] (unreleased)*
+* Deprecate :name_prefix in the new router DSL [José Valim]
+
* Add shallow routes back to the new router [Diego Carrion, Andrew White]
resources :posts do
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index c31f681411..e0d18b74d8 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -299,6 +299,11 @@ module ActionDispatch
options = args.extract_options!
options = options.dup
+ if name_prefix = options.delete(:name_prefix)
+ options[:as] ||= name_prefix
+ ActiveSupport::Deprecation.warn ":name_prefix was deprecated in the new router syntax. Use :as instead.", caller
+ end
+
case args.first
when String
options[:path] = args.first
@@ -343,7 +348,7 @@ module ActionDispatch
def namespace(path)
path = path.to_s
- scope(:path => path, :name_prefix => path, :module => path, :shallow_path => path, :shallow_prefix => path) { yield }
+ scope(:path => path, :as => path, :module => path, :shallow_path => path, :shallow_prefix => path) { yield }
end
def constraints(constraints = {})
@@ -359,10 +364,10 @@ module ActionDispatch
options = (@scope[:options] || {}).merge(options)
- if @scope[:name_prefix] && !options[:as].blank?
- options[:as] = "#{@scope[:name_prefix]}_#{options[:as]}"
- elsif @scope[:name_prefix] && options[:as] == ""
- options[:as] = @scope[:name_prefix].to_s
+ if @scope[:as] && !options[:as].blank?
+ options[:as] = "#{@scope[:as]}_#{options[:as]}"
+ elsif @scope[:as] && options[:as] == ""
+ options[:as] = @scope[:as].to_s
end
args.push(options)
@@ -382,7 +387,7 @@ module ActionDispatch
Mapper.normalize_path("#{parent}/#{child}")
end
- def merge_name_prefix_scope(parent, child)
+ def merge_as_scope(parent, child)
parent ? "#{parent}_#{child}" : child
end
@@ -435,6 +440,7 @@ module ActionDispatch
@name = entities.to_s
@path = options.delete(:path) || @name
@controller = options.delete(:controller) || @name.to_s.pluralize
+ @as = options.delete(:as)
@options = options
end
@@ -453,7 +459,7 @@ module ActionDispatch
end
def name
- options[:as] || @name
+ @as || @name
end
def plural
@@ -505,7 +511,7 @@ module ActionDispatch
def nested_options
{}.tap do |opts|
- opts[:name_prefix] = member_name
+ opts[:as] = member_name
opts["#{singular}_id".to_sym] = id_constraint if id_constraint?
opts[:options] = { :shallow => shallow? } unless options[:shallow].nil?
end
@@ -537,14 +543,10 @@ module ActionDispatch
[:show, :create, :update, :destroy, :new, :edit]
end
- def initialize(entity, options = {})
- super
- end
-
def member_name
name
end
- alias_method :collection_name, :member_name
+ alias :collection_name :member_name
def nested_path
path
@@ -552,7 +554,7 @@ module ActionDispatch
def nested_options
{}.tap do |opts|
- opts[:name_prefix] = member_name
+ opts[:as] = member_name
opts[:options] = { :shallow => shallow? } unless @options[:shallow].nil?
end
end
@@ -673,7 +675,7 @@ module ActionDispatch
if @scope[:shallow_path].blank?
scope(*parent_resource.nested_scope) { yield }
else
- scope(@scope[:shallow_path], :name_prefix => @scope[:shallow_prefix]) do
+ scope(@scope[:shallow_path], :as => @scope[:shallow_prefix]) do
scope(*parent_resource.nested_scope) { yield }
end
end
@@ -758,7 +760,7 @@ module ActionDispatch
def root(options={})
if @scope[:scope_level] == :resources
with_scope_level(:nested) do
- scope(parent_resource.path, :name_prefix => parent_resource.collection_name) do
+ scope(parent_resource.path, :as => parent_resource.collection_name) do
super(options)
end
end
@@ -806,14 +808,14 @@ module ActionDispatch
def with_exclusive_scope
begin
- old_name_prefix, old_path = @scope[:name_prefix], @scope[:path]
- @scope[:name_prefix], @scope[:path] = nil, nil
+ old_name_prefix, old_path = @scope[:as], @scope[:path]
+ @scope[:as], @scope[:path] = nil, nil
with_scope_level(:exclusive) do
yield
end
ensure
- @scope[:name_prefix], @scope[:path] = old_name_prefix, old_path
+ @scope[:as], @scope[:path] = old_name_prefix, old_path
end
end
@@ -908,7 +910,7 @@ module ActionDispatch
end
def name_for_action(action)
- name_prefix = @scope[:name_prefix].blank? ? "" : "#{@scope[:name_prefix]}_"
+ name_prefix = @scope[:as].blank? ? "" : "#{@scope[:as]}_"
shallow_prefix = @scope[:shallow_prefix].blank? ? "" : "#{@scope[:shallow_prefix]}_"
case action
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 495255c22b..e250810168 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -70,7 +70,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
get 'admin/passwords' => "queenbee#passwords", :constraints => ::TestRoutingMapper::IpRestrictor
- scope 'pt', :name_prefix => 'pt' do
+ scope 'pt', :as => 'pt' do
resources :projects, :path_names => { :edit => 'editar', :new => 'novo' }, :path => 'projetos' do
post :preview, :on => :new
end
@@ -243,9 +243,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
controller :articles do
- scope '/articles', :name_prefix => 'article' do
+ scope '/articles', :as => 'article' do
scope :path => '/:title', :title => /[a-z]+/, :as => :with_title do
- match '/:id', :to => :with_id
+ match '/:id', :to => :with_id, :as => ""
end
end
end