Class: RuboCop::Cop::Obsession::Rails::CallbackOneMethod

Inherits:
Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/rubocop/cop/obsession/rails/callback_one_method.rb

Overview

This cop checks for Rails callbacks with multiple fields.

One method per callback definition makes the definition extra clear.

Examples:


# bad
after_create :notify_followers, :send_stats

# good
after_create :notify_followers
after_create :send_stats

Constant Summary collapse

MSG =
'Declare only one method per callback definition.'

Instance Method Summary collapse

Methods included from Helpers

#rails_callback?, #verb?

Instance Method Details

#on_send(node) ⇒ Object



28
29
30
# File 'lib/rubocop/cop/obsession/rails/callback_one_method.rb', line 28

def on_send(node)
  on_callback(node) { |callback| add_offense(node) if rails_callback?(callback.to_s) }
end