Class: RuboCop::Cop::Sidekiq::DateTimeArgument
- Inherits:
-
Base
- Object
- Base
- Base
- RuboCop::Cop::Sidekiq::DateTimeArgument
show all
- Includes:
- ArgumentTraversal
- Defined in:
- lib/rubocop/cop/sidekiq/date_time_argument.rb
Overview
Checks for Date/Time/DateTime objects passed to Sidekiq job methods.
Date and Time objects should be converted to strings or timestamps
before being passed to Sidekiq jobs to ensure proper serialization.
Constant Summary
collapse
- MSG =
'Do not pass Date/Time objects to Sidekiq jobs. ' \
'Convert to a string or timestamp first.'
- RESTRICT_ON_SEND =
PerformMethods.all
- TIME_METHODS =
%i[now current zone].freeze
- DATE_METHODS =
%i[today yesterday tomorrow current].freeze
Instance Method Summary
collapse
#active_job_class?, #perform_call?, #sidekiq_include?, #sidekiq_options_call?
Instance Method Details
#date_constructor?(node) ⇒ Object
44
45
46
|
# File 'lib/rubocop/cop/sidekiq/date_time_argument.rb', line 44
def_node_matcher :date_constructor?, <<~PATTERN
(send (const {nil? cbase} :Date) {#{DATE_METHODS.map(&:inspect).join(' ')}} ...)
PATTERN
|
#datetime_constructor?(node) ⇒ Object
49
50
51
|
# File 'lib/rubocop/cop/sidekiq/date_time_argument.rb', line 49
def_node_matcher :datetime_constructor?, <<~PATTERN
(send (const {nil? cbase} :DateTime) {:now :current :parse} ...)
PATTERN
|
#on_send(node) ⇒ Object
Also known as:
on_csend
53
54
55
56
57
|
# File 'lib/rubocop/cop/sidekiq/date_time_argument.rb', line 53
def on_send(node)
sidekiq_perform_call?(node) do |args|
check_arguments(args)
end
end
|
34
35
36
|
# File 'lib/rubocop/cop/sidekiq/date_time_argument.rb', line 34
def_node_matcher :sidekiq_perform_call?, <<~PATTERN
(send _ {#{RESTRICT_ON_SEND.map(&:inspect).join(' ')}} $...)
PATTERN
|
#time_constructor?(node) ⇒ Object
39
40
41
|
# File 'lib/rubocop/cop/sidekiq/date_time_argument.rb', line 39
def_node_matcher :time_constructor?, <<~PATTERN
(send (const {nil? cbase} :Time) {#{TIME_METHODS.map(&:inspect).join(' ')}} ...)
PATTERN
|