Class: RuboCop::Cop::Obsession::Rails::PrivateCallback
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Obsession::Rails::PrivateCallback
- Includes:
- Helpers, VisibilityHelp
- Defined in:
- lib/rubocop/cop/obsession/rails/private_callback.rb
Overview
This cop checks for callbacks methods that are not private.
Callback methods are usually never called outside of the class, so there is no reason to declare them in the public section. They should be private.
Constant Summary collapse
- MSG =
'Make callback method private'
Constants included from Helpers
Instance Method Summary collapse
Methods included from Helpers
Instance Method Details
#on_def(node) ⇒ Object
50 51 52 53 54 |
# File 'lib/rubocop/cop/obsession/rails/private_callback.rb', line 50 def on_def(node) if @callbacks.include?(node.method_name) && node_visibility(node) == :public add_offense(node, message: MSG) end end |
#on_new_investigation ⇒ Object
40 41 42 |
# File 'lib/rubocop/cop/obsession/rails/private_callback.rb', line 40 def on_new_investigation @callbacks = Set.new end |
#on_send(node) ⇒ Object
44 45 46 47 48 |
# File 'lib/rubocop/cop/obsession/rails/private_callback.rb', line 44 def on_send(node) on_callback(node) do |callback, method_name| @callbacks << method_name if rails_callback?(callback.to_s) end end |