File tree Expand file tree Collapse file tree 5 files changed +5
-27
lines changed
actionpack/lib/action_dispatch/http
activerecord/lib/active_record
activesupport/lib/active_support
railties/test/application Expand file tree Collapse file tree 5 files changed +5
-27
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ def controller_class_for(name)
87
87
controller_param = name . underscore
88
88
const_name = controller_param . camelize << "Controller"
89
89
begin
90
- ActiveSupport :: Dependencies . constantize ( const_name )
90
+ const_name . constantize
91
91
rescue NameError => error
92
92
if error . missing_name == const_name || const_name . start_with? ( "#{ error . missing_name } ::" )
93
93
raise MissingController . new ( error . message , error . name )
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
+ require "active_support/inflector"
3
4
require "active_support/core_ext/hash/indifferent_access"
4
5
5
6
module ActiveRecord
@@ -181,7 +182,7 @@ def sti_name
181
182
# It is used to find the class correspondent to the value stored in the inheritance column.
182
183
def sti_class_for ( type_name )
183
184
if store_full_sti_class && store_full_class_name
184
- ActiveSupport :: Dependencies . constantize ( type_name )
185
+ type_name . constantize
185
186
else
186
187
compute_type ( type_name )
187
188
end
@@ -203,7 +204,7 @@ def polymorphic_name
203
204
# It is used to find the class correspondent to the value stored in the polymorphic type column.
204
205
def polymorphic_class_for ( name )
205
206
if store_full_class_name
206
- ActiveSupport :: Dependencies . constantize ( name )
207
+ name . constantize
207
208
else
208
209
compute_type ( name )
209
210
end
@@ -235,7 +236,7 @@ def compute_type(type_name)
235
236
if type_name . start_with? ( "::" )
236
237
# If the type is prefixed with a scope operator then we assume that
237
238
# the type_name is an absolute reference.
238
- ActiveSupport :: Dependencies . constantize ( type_name )
239
+ type_name . constantize
239
240
else
240
241
type_candidate = @_type_candidates_cache [ type_name ]
241
242
if type_candidate && type_constant = ActiveSupport ::Dependencies . safe_constantize ( type_candidate )
Original file line number Diff line number Diff line change @@ -82,12 +82,6 @@ def search_for_file(path_suffix)
82
82
nil # Gee, I sure wish we had first_match ;-)
83
83
end
84
84
85
- # Get the reference for class named +name+.
86
- # Raises an exception if referenced class does not exist.
87
- def constantize ( name )
88
- Inflector . constantize ( name )
89
- end
90
-
91
85
# Get the reference for class named +name+ if one exists.
92
86
# Otherwise returns +nil+.
93
87
def safe_constantize ( name )
Original file line number Diff line number Diff line change @@ -16,10 +16,6 @@ def clear
16
16
end
17
17
end
18
18
19
- def constantize ( cpath )
20
- ActiveSupport ::Inflector . constantize ( cpath )
21
- end
22
-
23
19
def safe_constantize ( cpath )
24
20
ActiveSupport ::Inflector . safe_constantize ( cpath )
25
21
end
Original file line number Diff line number Diff line change @@ -61,19 +61,6 @@ class RESTfulController < ApplicationController
61
61
assert RESTfulController
62
62
end
63
63
64
- test "constantize returns the value stored in the constant" do
65
- app_file "app/models/admin/user.rb" , "class Admin::User; end"
66
- boot
67
-
68
- assert_same Admin ::User , deps . constantize ( "Admin::User" )
69
- end
70
-
71
- test "constantize raises if the constant is unknown" do
72
- boot
73
-
74
- assert_raises ( NameError ) { deps . constantize ( "Admin" ) }
75
- end
76
-
77
64
test "safe_constantize returns the value stored in the constant" do
78
65
app_file "app/models/admin/user.rb" , "class Admin::User; end"
79
66
boot
You can’t perform that action at this time.
0 commit comments