Class: RuboCop::Cop::Obsession::Rails::ShortAfterCommit
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Obsession::Rails::ShortAfterCommit
- Defined in:
- lib/rubocop/cop/obsession/rails/short_after_commit.rb
Overview
This cop checks for ‘after_commit` declarations that could be shorter.
Constant Summary collapse
- MSG =
'Use shorter %<prefer>s'
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rubocop/cop/obsession/rails/short_after_commit.rb', line 71 def on_send(node) return if !after_commit?(node) if after_commit_create?(node) add_offense(node, message: format(MSG, prefer: 'after_create_commit')) elsif after_commit_update?(node) add_offense(node, message: format(MSG, prefer: 'after_update_commit')) elsif after_commit_destroy?(node) add_offense(node, message: format(MSG, prefer: 'after_destroy_commit')) elsif after_commit_create_update?(node) add_offense(node, message: format(MSG, prefer: 'after_save_commit')) elsif after_commit_all_events?(node) add_offense(node, message: format(MSG, prefer: 'after_commit with no `on:` argument')) end end |