Class: RuboCop::Cop::Platanus::PunditInApplicationController

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/platanus/pundit_in_application_controller.rb

Overview

Pundit should not be included in specific controllers. Prefer including it in the ApplicationController instead.

Examples:

# bad
class ApplicationController < ActionController::Base
end

class FooController < ApplicationController
  include Pundit
end

# bad
class ApplicationController < ActionController::Base
end

class FooController < ApplicationController
  include Pundit::Authorization
end

# good
class ApplicationController < ActionController::Base
  include Pundit
end

class FooController < ApplicationController
end

# good
class ApplicationController < ActionController::Base
  include Pundit::Authorization
end

class FooController < ApplicationController
end

Constant Summary collapse

MSG =
'`Pundit` should be included only in the `ApplicationController`.'

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



58
59
60
61
62
63
# File 'lib/rubocop/cop/platanus/pundit_in_application_controller.rb', line 58

def on_class(node)
  pundit_include_node = get_include_pundit_node(node)
  return unless pundit_include_node && !application_controller?(node)

  add_offense(pundit_include_node)
end