Skip to content

Commit da2fbb2

Browse files
committed
Deprecate ActiveSupport::Configurable
This proposal is based on a [code review comment][]: > I think we should deprecate and remove this module. It is only used > once inside the framework, in a place that perhaps don't even need it > anymore and I don't think it adds much for our users. They would be > better served with their own config object that is just a hash. To achieve this outcome, replace the only internal occurrence of `ActiveSupport::Configurable` with a [class_attribute][]. Similarly, replace [config_accessor][] calls with class- and instance-level calls to [delegate][] for the readers and writers. [code review comment]: rails#53796 (comment) [class_attribute]: https://edgeapi.rubyonrails.org/classes/Class.html#method-i-class_attribute [config_accessor]: https://edgeapi.rubyonrails.org/classes/ActiveSupport/Configurable/ClassMethods.html#method-i-config_accessor [delegate]: https://edgeapi.rubyonrails.org/classes/Module.html#method-i-delegate
1 parent 71fbee7 commit da2fbb2

File tree

9 files changed

+44
-27
lines changed

9 files changed

+44
-27
lines changed

actionmailer/lib/action_mailer/railtie.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ class Railtie < Rails::Railtie # :nodoc:
7373
app.config.paths["test/mailers/previews"].concat(options.preview_paths)
7474
end
7575

76-
initializer "action_mailer.compile_config_methods" do
77-
ActiveSupport.on_load(:action_mailer) do
78-
config.compile_methods! if config.respond_to?(:compile_methods!)
79-
end
80-
end
81-
8276
config.after_initialize do |app|
8377
options = app.config.action_mailer
8478

actionpack/lib/abstract_controller/asset_paths.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ module AssetPaths # :nodoc:
77
extend ActiveSupport::Concern
88

99
included do
10-
config_accessor :asset_host, :assets_dir, :javascripts_dir,
11-
:stylesheets_dir, :default_asset_host_protocol, :relative_url_root
10+
singleton_class.delegate :asset_host, :asset_host=, :assets_dir, :assets_dir=, :javascripts_dir, :javascripts_dir=,
11+
:stylesheets_dir, :stylesheets_dir=, :default_asset_host_protocol, :default_asset_host_protocol=, :relative_url_root, :relative_url_root=, to: :config
12+
delegate :asset_host, :asset_host=, :assets_dir, :assets_dir=, :javascripts_dir, :javascripts_dir=,
13+
:stylesheets_dir, :stylesheets_dir=, :default_asset_host_protocol, :default_asset_host_protocol=, :relative_url_root, :relative_url_root=, to: :config
1214
end
1315
end
1416
end

actionpack/lib/abstract_controller/base.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# :markup: markdown
44

55
require "abstract_controller/error"
6-
require "active_support/configurable"
76
require "active_support/descendants_tracker"
87
require "active_support/core_ext/module/anonymous"
98
require "active_support/core_ext/module/attr_internal"
@@ -47,7 +46,7 @@ class Base
4746
# Returns the formats that can be processed by the controller.
4847
attr_internal :formats
4948

50-
include ActiveSupport::Configurable
49+
class_attribute :config, instance_predicate: false, default: ActiveSupport::OrderedOptions.new
5150
extend ActiveSupport::DescendantsTracker
5251

5352
class << self
@@ -65,6 +64,7 @@ def inherited(klass) # :nodoc:
6564
unless klass.instance_variable_defined?(:@abstract)
6665
klass.instance_variable_set(:@abstract, false)
6766
end
67+
klass.config = ActiveSupport::InheritableOptions.new(config)
6868
super
6969
end
7070

@@ -128,6 +128,10 @@ def controller_path
128128
@controller_path ||= name.delete_suffix("Controller").underscore unless anonymous?
129129
end
130130

131+
def configure # :nodoc:
132+
yield config
133+
end
134+
131135
# Refresh the cached action_methods when a new action_method is added.
132136
def method_added(name)
133137
super
@@ -201,6 +205,10 @@ def self.supports_path?
201205
true
202206
end
203207

208+
def config # :nodoc:
209+
@_config ||= self.class.config.inheritable_copy
210+
end
211+
204212
def inspect # :nodoc:
205213
"#<#{self.class.name}:#{'%#016x' % (object_id << 1)}>"
206214
end

actionpack/lib/abstract_controller/caching.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ def cache_configured?
3232
included do
3333
extend ConfigMethods
3434

35-
config_accessor :default_static_extension
35+
singleton_class.delegate :default_static_extension, :default_static_extension=, to: :config
36+
delegate :default_static_extension, :default_static_extension=, to: :config
3637
self.default_static_extension ||= ".html"
3738

38-
config_accessor :perform_caching
39+
singleton_class.delegate :perform_caching, :perform_caching=, to: :config
40+
delegate :perform_caching, :perform_caching=, to: :config
3941
self.perform_caching = true if perform_caching.nil?
4042

41-
config_accessor :enable_fragment_cache_logging
43+
singleton_class.delegate :enable_fragment_cache_logging, :enable_fragment_cache_logging=, to: :config
44+
delegate :enable_fragment_cache_logging, :enable_fragment_cache_logging=, to: :config
4245
self.enable_fragment_cache_logging = false
4346

4447
class_attribute :_view_cache_dependencies, default: []

actionpack/lib/abstract_controller/logger.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module Logger # :nodoc:
99
extend ActiveSupport::Concern
1010

1111
included do
12-
config_accessor :logger
12+
singleton_class.delegate :logger, :logger=, to: :config
13+
delegate :logger, :logger=, to: :config
1314
include ActiveSupport::Benchmarkable
1415
end
1516
end

actionpack/lib/action_controller/metal/request_forgery_protection.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,32 +71,39 @@ module RequestForgeryProtection
7171
included do
7272
# Sets the token parameter name for RequestForgery. Calling
7373
# `protect_from_forgery` sets it to `:authenticity_token` by default.
74-
config_accessor :request_forgery_protection_token
74+
singleton_class.delegate :request_forgery_protection_token, :request_forgery_protection_token=, to: :config
75+
delegate :request_forgery_protection_token, :request_forgery_protection_token=, to: :config
7576
self.request_forgery_protection_token ||= :authenticity_token
7677

7778
# Holds the class which implements the request forgery protection.
78-
config_accessor :forgery_protection_strategy
79+
singleton_class.delegate :forgery_protection_strategy, :forgery_protection_strategy=, to: :config
80+
delegate :forgery_protection_strategy, :forgery_protection_strategy=, to: :config
7981
self.forgery_protection_strategy = nil
8082

8183
# Controls whether request forgery protection is turned on or not. Turned off by
8284
# default only in test mode.
83-
config_accessor :allow_forgery_protection
85+
singleton_class.delegate :allow_forgery_protection, :allow_forgery_protection=, to: :config
86+
delegate :allow_forgery_protection, :allow_forgery_protection=, to: :config
8487
self.allow_forgery_protection = true if allow_forgery_protection.nil?
8588

8689
# Controls whether a CSRF failure logs a warning. On by default.
87-
config_accessor :log_warning_on_csrf_failure
90+
singleton_class.delegate :log_warning_on_csrf_failure, :log_warning_on_csrf_failure=, to: :config
91+
delegate :log_warning_on_csrf_failure, :log_warning_on_csrf_failure=, to: :config
8892
self.log_warning_on_csrf_failure = true
8993

9094
# Controls whether the Origin header is checked in addition to the CSRF token.
91-
config_accessor :forgery_protection_origin_check
95+
singleton_class.delegate :forgery_protection_origin_check, :forgery_protection_origin_check=, to: :config
96+
delegate :forgery_protection_origin_check, :forgery_protection_origin_check=, to: :config
9297
self.forgery_protection_origin_check = false
9398

9499
# Controls whether form-action/method specific CSRF tokens are used.
95-
config_accessor :per_form_csrf_tokens
100+
singleton_class.delegate :per_form_csrf_tokens, :per_form_csrf_tokens=, to: :config
101+
delegate :per_form_csrf_tokens, :per_form_csrf_tokens=, to: :config
96102
self.per_form_csrf_tokens = false
97103

98104
# The strategy to use for storing and retrieving CSRF tokens.
99-
config_accessor :csrf_token_storage_strategy
105+
singleton_class.delegate :csrf_token_storage_strategy, :csrf_token_storage_strategy=, to: :config
106+
delegate :csrf_token_storage_strategy, :csrf_token_storage_strategy=, to: :config
100107
self.csrf_token_storage_strategy = SessionStore.new
101108

102109
helper_method :form_authenticity_token

actionpack/lib/action_controller/railtie.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ class Railtie < Rails::Railtie # :nodoc:
9393
end
9494
end
9595

96-
initializer "action_controller.compile_config_methods" do
97-
ActiveSupport.on_load(:action_controller) do
98-
config.compile_methods! if config.respond_to?(:compile_methods!)
99-
end
100-
end
101-
10296
initializer "action_controller.request_forgery_protection" do |app|
10397
ActiveSupport.on_load(:action_controller_base) do
10498
if app.config.action_controller.default_protect_from_forgery

activesupport/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Deprecate `ActiveSupport::Configurable`
2+
3+
*Sean Doyle*
4+
15
* `nil.to_query("key")` now returns `key`.
26

37
Previously it would return `key=`, preventing round tripping with `Rack::Utils.parse_nested_query`.

activesupport/lib/active_support.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ module ActiveSupport
9191
autoload :SafeBuffer, "active_support/core_ext/string/output_safety"
9292
autoload :TestCase
9393

94+
include Deprecation::DeprecatedConstantAccessor
95+
96+
deprecate_constant :Configurable, "class_attribute :config, default: {}", deprecator: ActiveSupport.deprecator
97+
9498
def self.eager_load!
9599
super
96100

0 commit comments

Comments
 (0)