Skip to content

Commit 9825729

Browse files
committed
Refactor railtie.
1 parent 289d14d commit 9825729

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

lib/jsonapi/rails/railtie.rb

+16-14
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,27 @@ class Railtie < ::Rails::Railtie
1616
jsonapi_error: ErrorsRenderer.new
1717
}.freeze
1818

19-
initializer 'jsonapi-rails.action_controller' do
20-
ActiveSupport.on_load(:action_controller) do
21-
if JSONAPI::Rails.config.extend_action_controller
22-
include ::JSONAPI::Rails::Controller
23-
end
19+
initializer 'jsonapi.init', after: :load_config_initializers do
20+
if JSONAPI::Rails.config.register_mime_type
21+
Mime::Type.register MEDIA_TYPE, :jsonapi
22+
end
2423

25-
if JSONAPI::Rails.config.register_mime_type
26-
Mime::Type.register MEDIA_TYPE, :jsonapi
24+
if JSONAPI::Rails.config.register_parameter_parser
25+
if ::Rails::VERSION::MAJOR >= 5
26+
::ActionDispatch::Request.parameter_parsers[:jsonapi] = PARSER
27+
else
28+
::ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime[:jsonapi]] = PARSER
2729
end
30+
end
2831

29-
if JSONAPI::Rails.config.register_parameter_parser
30-
if ::Rails::VERSION::MAJOR >= 5
31-
::ActionDispatch::Request.parameter_parsers[:jsonapi] = PARSER
32-
else
33-
::ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime[:jsonapi]] = PARSER
34-
end
32+
if JSONAPI::Rails.config.extend_action_controller
33+
ActiveSupport.on_load(:action_controller) do
34+
include ::JSONAPI::Rails::Controller
3535
end
36+
end
3637

37-
if JSONAPI::Rails.config.register_renderers
38+
if JSONAPI::Rails.config.register_renderers
39+
ActiveSupport.on_load(:action_controller) do
3840
RENDERERS.each do |name, renderer|
3941
::ActionController::Renderers.add(name) do |resources, options|
4042
# Renderer proc is evaluated in the controller context.

0 commit comments

Comments
 (0)