Class: RuboCop::Cop::Legion::Extension::HookMissingRunnerClass

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/legion/extension/hook_missing_runner_class.rb

Overview

Detects hook classes inside a ‘Hooks` namespace that do not override `runner_class`. Without this override, the framework hook builder dispatches to nil, causing HTTP 500 errors.

Examples:

# bad
module Hooks
  class Auth
    def handle(request)
      { status: 200 }
    end
  end
end

# good
module Hooks
  class Auth
    def runner_class
      Runners::Auth
    end

    def handle(request)
      { status: 200 }
    end
  end
end

Constant Summary collapse

MSG =
'Hook classes must override `runner_class`. Without it, the framework dispatches to nil.'

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



36
37
38
39
40
41
# File 'lib/rubocop/cop/legion/extension/hook_missing_runner_class.rb', line 36

def on_class(node)
  return unless inside_hooks_namespace?(node)
  return if defines_runner_class?(node)

  add_offense(node.identifier)
end