Class: RuboCop::Cop::Cuseum::InheritFromBaseService

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/cuseum/inherit_from_base_service.rb

Overview

Ensures that service classes in app/services inherit from BaseService directly or indirectly.

Examples:

# good - direct inheritance
class UserService < BaseService
  def call
    # ...
  end
end

# good - indirect inheritance
class ApplicationService < BaseService
end

class UserService < ApplicationService
  def call
    # ...
  end
end

# bad - no inheritance from BaseService
class UserService
  def call
    # ...
  end
end

# bad - inherits from something else
class UserService < SomeOtherClass
  def call
    # ...
  end
end

Constant Summary collapse

MSG =
"Service classes must inherit from BaseService directly or indirectly."

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



44
45
46
47
48
# File 'lib/rubocop/cop/cuseum/inherit_from_base_service.rb', line 44

def on_class(node)
  return if inherits_from_base_service?(node)

  add_offense(node, message: MSG)
end