Class: RuboCop::Cop::ThreadSafety::ClassInstanceVariable
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::ThreadSafety::ClassInstanceVariable
- Defined in:
- lib/rubocop/cop/thread_safety/class_instance_variable.rb
Overview
Avoid class instance variables.
Constant Summary collapse
- MSG =
'Avoid class instance variables.'
- RESTRICT_ON_SEND =
%i[ instance_variable_set instance_variable_get ].freeze
Instance Method Summary collapse
- #instance_variable_get_call?(node) ⇒ Object
- #instance_variable_set_call?(node) ⇒ Object
- #on_ivar(node) ⇒ Object (also: #on_ivasgn)
- #on_send(node) ⇒ Object
Instance Method Details
#instance_variable_get_call?(node) ⇒ Object
77 78 79 |
# File 'lib/rubocop/cop/thread_safety/class_instance_variable.rb', line 77 def_node_matcher :instance_variable_get_call?, <<~MATCHER (send nil? :instance_variable_get (...)) MATCHER |
#instance_variable_set_call?(node) ⇒ Object
72 73 74 |
# File 'lib/rubocop/cop/thread_safety/class_instance_variable.rb', line 72 def_node_matcher :instance_variable_set_call?, <<~MATCHER (send nil? :instance_variable_set (...) (...)) MATCHER |
#on_ivar(node) ⇒ Object Also known as: on_ivasgn
81 82 83 84 85 86 87 |
# File 'lib/rubocop/cop/thread_safety/class_instance_variable.rb', line 81 def on_ivar(node) return unless class_method_definition?(node) return if method_definition?(node) return if synchronized?(node) add_offense(node.loc.name) end |
#on_send(node) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/rubocop/cop/thread_safety/class_instance_variable.rb', line 90 def on_send(node) return unless instance_variable_call?(node) return unless class_method_definition?(node) return if method_definition?(node) return if synchronized?(node) add_offense(node) end |