Class: RuboCop::Cop::Obsession::Rails::ServiceName
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Obsession::Rails::ServiceName
- Includes:
- Helpers
- Defined in:
- lib/rubocop/cop/obsession/rails/service_name.rb
Overview
This cop checks for services and jobs whose name do not start with a verb.
Services and jobs with only one public method should have a name that starts with a verb, because these classes are essentially performing one action, and the best way to describe an action is with a verb.
Direct Known Subclasses
Constant Summary collapse
- MSG =
'Service or Job name should start with a verb.'
- IGNORED_PUBLIC_METHODS =
%i[initialize lock_period].freeze
Constants included from Helpers
Instance Method Summary collapse
Methods included from Helpers
Instance Method Details
#on_class(class_node) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/rubocop/cop/obsession/rails/service_name.rb', line 52 def on_class(class_node) return if public_methods(class_node).length != 1 class_name = class_node.identifier.source class_name_first_word = class_name.underscore.split('_').first add_offense(class_node) if !verb?(class_name_first_word) end |