Class: Rubopolis::Cop::TimeUsage
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Rubopolis::Cop::TimeUsage
- Defined in:
- lib/rubopolis/cop/time_usage.rb
Overview
Constant Summary collapse
- USAGE_MSG =
'`Time.zone.now` or `Time.zone.today` should not be used, to consider Time.current or ' \ 'Date.current instead: see lib/custom_cops/time_usage'
- ARITHMETIC_MSG =
'Avoid subtracting or adding for Time, to use methods like `ago` and `since/from_now` e.g. ' \ '`2.weeks.ago`, `5.minutes.since`. Refer to https://api.rubyonrails.org/classes/Time.html ' \ 'for more info'
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rubopolis/cop/time_usage.rb', line 45 def on_send(node) if time_now?(node) || time_today?(node) = USAGE_MSG elsif time_addition?(node) || time_subtract?(node) = ARITHMETIC_MSG else return end add_offense(node, message: ) end |