Class: RuboCop::Cop::Seams::KnownQueueNames

Inherits:
Base
  • Object
show all
Defined in:
lib/seams/cops/known_queue_names.rb

Overview

Ensures every ‘queue_as` call uses a queue name that has been registered in the host application’s ‘.rubocop.yml`. Catches typos and prevents jobs from being silently routed to a queue that no worker is listening on.

Constant Summary collapse

MSG =
"Queue `%<name>s` is not registered. Add it to .rubocop.yml " \
"under Seams/KnownQueueNames#KnownQueues, or pick one of: %<known>s."

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/seams/cops/known_queue_names.rb', line 21

def on_send(node)
  literal = queue_as_literal?(node)
  return unless literal

  name = literal.value.to_s
  return if known_queues.include?(name)

  add_offense(
    node,
    message: format(MSG, name: name, known: known_queues.join(", "))
  )
end

#queue_as_literal?(node) ⇒ Object



17
18
19
# File 'lib/seams/cops/known_queue_names.rb', line 17

def_node_matcher :queue_as_literal?, <<~PATTERN
  (send nil? :queue_as ${sym str})
PATTERN