Skip to content

Commit 6499cdd

Browse files
committed
Rename url_helper to direct
1 parent 5e1c722 commit 6499cdd

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,20 +2020,20 @@ def concerns(*args)
20202020
end
20212021
end
20222022

2023-
module UrlHelpers
2023+
module DirectUrls
20242024
# Define a custom url helper that will be added to the url helpers
20252025
# module. This allows you override and/or replace the default behavior
20262026
# of routing helpers, e.g:
20272027
#
2028-
# url_helper :homepage do
2028+
# direct :homepage do
20292029
# "http://www.rubyonrails.org"
20302030
# end
20312031
#
2032-
# url_helper :commentable do |model|
2032+
# direct :commentable do |model|
20332033
# [ model, anchor: model.dom_id ]
20342034
# end
20352035
#
2036-
# url_helper :main do
2036+
# direct :main do
20372037
# { controller: 'pages', action: 'index', subdomain: 'www' }
20382038
# end
20392039
#
@@ -2049,13 +2049,13 @@ module UrlHelpers
20492049
# You can also specify default options that will be passed through to
20502050
# your url helper definition, e.g:
20512051
#
2052-
# url_helper :browse, page: 1, size: 10 do |options|
2052+
# direct :browse, page: 1, size: 10 do |options|
20532053
# [ :products, options.merge(params.permit(:page, :size)) ]
20542054
# end
20552055
#
20562056
# NOTE: It is the url helper's responsibility to return the correct
20572057
# set of options to be passed to the `url_for` call.
2058-
def url_helper(name, options = {}, &block)
2058+
def direct(name, options = {}, &block)
20592059
@set.add_url_helper(name, options, &block)
20602060
end
20612061
end
@@ -2153,7 +2153,7 @@ def initialize(set) #:nodoc:
21532153
include Scoping
21542154
include Concerns
21552155
include Resources
2156-
include UrlHelpers
2156+
include DirectUrls
21572157
end
21582158
end
21592159
end

actionpack/test/dispatch/routing/custom_url_helpers_test.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ class Product < Linkable; end
3030
get '/dashboard', to: 'dashboard#index'
3131
end
3232

33-
url_helper(:website) { "http://www.rubyonrails.org" }
34-
url_helper(:linkable) { |linkable| [:"#{linkable.linkable_type}", { id: linkable.id }] }
35-
url_helper(:params) { |params| params }
36-
url_helper(:symbol) { :basket }
37-
url_helper(:hash) { { controller: "basket", action: "show" } }
38-
url_helper(:array) { [:admin, :dashboard] }
39-
url_helper(:options) { |options| [:products, options] }
40-
url_helper(:defaults, size: 10) { |options| [:products, options] }
33+
direct(:website) { "http://www.rubyonrails.org" }
34+
direct(:linkable) { |linkable| [:"#{linkable.linkable_type}", { id: linkable.id }] }
35+
direct(:params) { |params| params }
36+
direct(:symbol) { :basket }
37+
direct(:hash) { { controller: "basket", action: "show" } }
38+
direct(:array) { [:admin, :dashboard] }
39+
direct(:options) { |options| [:products, options] }
40+
direct(:defaults, size: 10) { |options| [:products, options] }
4141
end
4242

4343
APP = build_app Routes
@@ -57,7 +57,7 @@ def setup
5757
@safe_params = ActionController::Parameters.new(@path_params).permit(:controller, :action)
5858
end
5959

60-
def test_custom_path_helper
60+
def test_direct_paths
6161
assert_equal "http://www.rubyonrails.org", website_path
6262
assert_equal "http://www.rubyonrails.org", Routes.url_helpers.website_path
6363

@@ -88,7 +88,7 @@ def test_custom_path_helper
8888
assert_equal "/products?size=20", Routes.url_helpers.defaults_path(size: 20)
8989
end
9090

91-
def test_custom_url_helper
91+
def test_direct_urls
9292
assert_equal "http://www.rubyonrails.org", website_url
9393
assert_equal "http://www.rubyonrails.org", Routes.url_helpers.website_url
9494

@@ -108,8 +108,8 @@ def test_custom_url_helper
108108
assert_equal "http://www.example.com/basket", Routes.url_helpers.symbol_url
109109
assert_equal "http://www.example.com/basket", hash_url
110110
assert_equal "http://www.example.com/basket", Routes.url_helpers.hash_url
111-
assert_equal "/admin/dashboard", array_path
112-
assert_equal "/admin/dashboard", Routes.url_helpers.array_path
111+
assert_equal "http://www.example.com/admin/dashboard", array_url
112+
assert_equal "http://www.example.com/admin/dashboard", Routes.url_helpers.array_url
113113

114114
assert_equal "http://www.example.com/products?page=2", options_url(page: 2)
115115
assert_equal "http://www.example.com/products?page=2", Routes.url_helpers.options_url(page: 2)

railties/test/application/routing_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def custom
289289
get 'foo', to: 'foo#bar'
290290
get 'custom', to: 'foo#custom'
291291
292-
url_helper(:custom) { "http://www.microsoft.com" }
292+
direct(:custom) { "http://www.microsoft.com" }
293293
end
294294
RUBY
295295

@@ -306,7 +306,7 @@ def custom
306306
get 'foo', to: 'foo#baz'
307307
get 'custom', to: 'foo#custom'
308308
309-
url_helper(:custom) { "http://www.apple.com" }
309+
direct(:custom) { "http://www.apple.com" }
310310
end
311311
RUBY
312312

@@ -466,7 +466,7 @@ def index
466466
app_file "config/routes.rb", <<-RUBY
467467
Rails.application.routes.draw do
468468
get ':locale/foo', to: 'foo#index', as: 'foo'
469-
url_helper(:microsoft) { 'http://www.microsoft.com' }
469+
direct(:microsoft) { 'http://www.microsoft.com' }
470470
end
471471
RUBY
472472

@@ -478,7 +478,7 @@ def index
478478
app_file "config/routes.rb", <<-RUBY
479479
Rails.application.routes.draw do
480480
get ':locale/bar', to: 'bar#index', as: 'foo'
481-
url_helper(:apple) { 'http://www.apple.com' }
481+
direct(:apple) { 'http://www.apple.com' }
482482
end
483483
RUBY
484484

0 commit comments

Comments
 (0)