Skip to content

Conditionally include controller mixin #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
# config.register_mime_type = true
# config.register_param_parser = true
# config.register_renderers = true
# config.extend_action_controller = true
end
3 changes: 2 additions & 1 deletion lib/jsonapi/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class Configuration < ActiveSupport::InheritableOptions; end
DEFAULT_CONFIG = {
register_parameter_parser: true,
register_mime_type: true,
register_renderers: true
register_renderers: true,
extend_action_controller: true
}.freeze

def self.configure
Expand Down
28 changes: 16 additions & 12 deletions lib/jsonapi/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ class Railtie < ::Rails::Railtie
jsonapi_error: ErrorsRenderer.new
}.freeze

initializer 'jsonapi-rails.action_controller' do
ActiveSupport.on_load(:action_controller) do
include ::JSONAPI::Rails::Controller
initializer 'jsonapi.init', after: :load_config_initializers do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block has too many lines. [29/25]

if JSONAPI::Rails.config.register_mime_type
Mime::Type.register MEDIA_TYPE, :jsonapi
end

if JSONAPI::Rails.config.register_mime_type
Mime::Type.register MEDIA_TYPE, :jsonapi
if JSONAPI::Rails.config.register_parameter_parser
if ::Rails::VERSION::MAJOR >= 5
::ActionDispatch::Request.parameter_parsers[:jsonapi] = PARSER
else
::ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime[:jsonapi]] = PARSER

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [84/80]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [84/80]

end
end

if JSONAPI::Rails.config.register_parameter_parser
if ::Rails::VERSION::MAJOR >= 5
::ActionDispatch::Request.parameter_parsers[:jsonapi] = PARSER
else
::ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime[:jsonapi]] = PARSER
end
if JSONAPI::Rails.config.extend_action_controller
ActiveSupport.on_load(:action_controller) do
include ::JSONAPI::Rails::Controller
end
end

if JSONAPI::Rails.config.register_renderers
if JSONAPI::Rails.config.register_renderers
ActiveSupport.on_load(:action_controller) do
RENDERERS.each do |name, renderer|
::ActionController::Renderers.add(name) do |resources, options|
# Renderer proc is evaluated in the controller context.
Expand Down