class RuboCop::Cop::ThreadSafety::ClassAndModuleAttributes
end
cattr_accessor :current_user
class User
# bad
@example
They are implemented by class variables, which are not thread-safe.
Avoid mutating class and module attributes.
def class_attribute_allowed?
def class_attribute_allowed? cop_config['ActiveSupportClassAttributeAllowed'] end
def defined_in_singleton_class?(node)
def defined_in_singleton_class?(node) node.ancestors.each do |ancestor| case ancestor.type when :def then return false when :sclass then return true else next end end false end
def on_send(node) # rubocop:disable InternalAffairs/OnSendWithoutOnCSend
def on_send(node) # rubocop:disable InternalAffairs/OnSendWithoutOnCSend return unless mattr?(node) || (!class_attribute_allowed? && class_attr?(node)) || singleton_attr?(node) add_offense(node) end
def singleton_attr?(node)
def singleton_attr?(node) (attr?(node) || attr_internal?(node)) && defined_in_singleton_class?(node) end