Skip to content

Commit ea8d463

Browse files
dgynnbf4
authored andcommitted
use action_controller configuration options in initializers
this uses the configuration settings rather than calling ActionController::Base to get the configured values. after the "action_controller.set_configs" initializer has run, the configuration option holds the value Base will get when it loads.
1 parent 58a74d0 commit ea8d463

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

lib/active_model_serializers/railtie.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ class Railtie < Rails::Railtie
1010
end
1111

1212
initializer 'active_model_serializers.action_controller' do
13-
ActiveSupport.run_load_hooks(:active_model_serializers, ActiveModelSerializers)
14-
ActionController::Base.send(:include, ::ActionController::Serialization)
13+
ActiveSupport.on_load(:action_controller) do
14+
ActionController::Base.send(:include, ::ActionController::Serialization)
15+
end
1516
end
1617

17-
initializer 'active_model_serializers.logger' do
18-
ActiveSupport.on_load(:active_model_serializers) do
19-
self.logger = ActionController::Base.logger
20-
end
18+
initializer 'active_model_serializers.logger', :after => 'action_controller.set_configs' do
19+
ActiveModelSerializers.logger = Rails.configuration.action_controller.logger
2120
end
2221

2322
# To be useful, this hook must run after Rails has initialized,
@@ -30,8 +29,8 @@ class Railtie < Rails::Railtie
3029
# inheritable, we don't want to set it on `ActiveModel::Serializer` directly unless
3130
# we want *every* serializer to be considered cacheable, regardless of specifying
3231
# `cache # some options` in a serializer or not.
33-
initializer 'active_model_serializers.caching' => :after_initialize do
34-
ActiveModelSerializers.config.cache_store = ActionController::Base.cache_store
32+
initializer 'active_model_serializers.caching', :after => 'action_controller.set_configs' do
33+
ActiveModelSerializers.config.cache_store = Rails.configuration.action_controller.cache_store
3534
ActiveModelSerializers.config.perform_caching = Rails.configuration.action_controller.perform_caching
3635
end
3736

test/test_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
require 'fixtures/poro'
5959

60-
ActiveSupport.on_load(:active_model_serializers) do
60+
ActiveSupport.on_load(:action_controller) do
6161
$action_controller_logger = ActiveModelSerializers.logger
6262
ActiveModelSerializers.logger = Logger.new(IO::NULL)
6363
end

0 commit comments

Comments
 (0)