Class: RuboCop::Cop::Platanus::NoCommand

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/platanus/no_command.rb

Overview

Usage of PowerTypes::Command is no longer recommended. Rails ApplicationJob should be used instead.

Examples:


# bad
class ExecuteSomeAction < PowerTypes::Command.new(:foo, :bar)
  def perform
    # Command code goes here
  end
 end

# good
class GuestsCleanupJob < ApplicationJob
  def perform
    # Job code goes here
  end
end

Constant Summary collapse

MSG =
'Use `ApplicationJob` instead of `PowerTypes::Command`.'

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



33
34
35
36
37
# File 'lib/rubocop/cop/platanus/no_command.rb', line 33

def on_class(node)
  return unless uses_powertypes_command?(node)

  add_offense(node)
end

#uses_powertypes_command?(node) ⇒ Object



29
30
31
# File 'lib/rubocop/cop/platanus/no_command.rb', line 29

def_node_matcher :uses_powertypes_command?, <<~PATTERN
  (class _ (send (const (const _ :PowerTypes) :Command) :new ...) _)
PATTERN