Class: RuboCop::Cop::Obsession::Rails::ServicePerformMethod
- Inherits:
-
ServiceName
- Object
- Base
- ServiceName
- RuboCop::Cop::Obsession::Rails::ServicePerformMethod
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/obsession/rails/service_perform_method.rb
Overview
This cop checks for services whose single public method is not named perform.
Services and jobs with only one public method should have their method named perform for consistency. The choice of perform as a name is inspired from ActiveJob and makes it easier to make services and jobs interchangeable.
Constant Summary collapse
- MSG =
'Single public method of Service should be called `perform`'
Constants inherited from ServiceName
RuboCop::Cop::Obsession::Rails::ServiceName::IGNORED_PUBLIC_METHODS
Instance Method Summary collapse
Methods included from Helpers
Instance Method Details
#on_class(class_node) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rubocop/cop/obsession/rails/service_perform_method.rb', line 41 def on_class(class_node) public_methods = public_methods(class_node) return if public_methods.length != 1 method = public_methods.first if method.method_name != :perform add_offense(method) do |corrector| corrector.replace(method, method.source.sub(method.method_name.to_s, 'perform')) end end end |