Skip to content

Commit 5b93ef5

Browse files
committed
Rename url_helper to direct
1 parent 419c715 commit 5b93ef5

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,20 +2015,20 @@ def concerns(*args)
20152015
end
20162016
end
20172017

2018-
module UrlHelpers
2018+
module DirectUrls
20192019
# Define a custom url helper that will be added to the url helpers
20202020
# module. This allows you override and/or replace the default behavior
20212021
# of routing helpers, e.g:
20222022
#
2023-
# url_helper :homepage do
2023+
# direct :homepage do
20242024
# "http://www.rubyonrails.org"
20252025
# end
20262026
#
2027-
# url_helper :commentable do |model|
2027+
# direct :commentable do |model|
20282028
# [ model, anchor: model.dom_id ]
20292029
# end
20302030
#
2031-
# url_helper :main do
2031+
# direct :main do
20322032
# { controller: 'pages', action: 'index', subdomain: 'www' }
20332033
# end
20342034
#
@@ -2044,13 +2044,13 @@ module UrlHelpers
20442044
# You can also specify default options that will be passed through to
20452045
# your url helper definition, e.g:
20462046
#
2047-
# url_helper :browse, page: 1, size: 10 do |options|
2047+
# direct :browse, page: 1, size: 10 do |options|
20482048
# [ :products, options.merge(params.permit(:page, :size)) ]
20492049
# end
20502050
#
20512051
# NOTE: It is the url helper's responsibility to return the correct
20522052
# set of options to be passed to the `url_for` call.
2053-
def url_helper(name, options = {}, &block)
2053+
def direct(name, options = {}, &block)
20542054
@set.add_url_helper(name, options, &block)
20552055
end
20562056
end
@@ -2149,7 +2149,7 @@ def initialize(set) #:nodoc:
21492149
include Scoping
21502150
include Concerns
21512151
include Resources
2152-
include UrlHelpers
2152+
include DirectUrls
21532153
end
21542154
end
21552155
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)

0 commit comments

Comments
 (0)