Class: RuboCop::Cop::YiffSpace::CurrentOutsideOfRequests
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::YiffSpace::CurrentOutsideOfRequests
- Defined in:
- lib/rubocop/cop/yiff_space/current_outside_of_requests.rb
Overview
Prevents use of the Current class outside of the request cycle. Current relies on thread-local state set by request middleware and is unavailable in background jobs, rake tasks, or other contexts outside of the request lifecycle.
The class name is configurable via ClassName (default: Current).
References inside the class that defines Current itself are always
ignored. Controllers, views, helpers, presenters, and decorators are
excluded by default. Use IgnoredMethods, IgnoredMethodPrefixes,
IgnoredMethodSuffixes, or IgnoredMethodPatterns to allow
Current in specific methods in checked files.
Constant Summary collapse
- MSG =
"`%<class_name>s` should only be used within the request cycle (controllers, views, helpers, decorators)"
Instance Method Summary collapse
Instance Method Details
#on_const(node) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/rubocop/cop/yiff_space/current_outside_of_requests.rb', line 66 def on_const(node) return unless current?(node) return if ignored_method?(node) return if inside_current_class?(node) return if node.parent&.send_type? && node.parent.receiver == node add_offense(node, message: ) end |
#on_csend(node) ⇒ Object
62 63 64 |
# File 'lib/rubocop/cop/yiff_space/current_outside_of_requests.rb', line 62 def on_csend(node) on_send(node) end |
#on_send(node) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/rubocop/cop/yiff_space/current_outside_of_requests.rb', line 54 def on_send(node) return unless starts_with_current?(node) return if ignored_method?(node) return if inside_current_class?(node) add_offense(node, message: ) end |