Class: RuboCop::Cop::Legion::Extension::EveryActorRequiresTime

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/legion/extension/every_actor_requires_time.rb

Overview

Detects actor classes that inherit from Every or Poll but do not call the time DSL method. Without time, the framework has no interval and the actor will not schedule correctly.

Examples:

# bad
module Actor
  class Foo < Legion::Extensions::Actors::Every
  end
end

# good
module Actor
  class Foo < Legion::Extensions::Actors::Every
    time 60
  end
end

Constant Summary collapse

MSG =
'Every/Poll actors must call the `time` DSL method to set the interval.'
INTERVAL_BASES =
%i[Every Poll].to_set.freeze

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/rubocop/cop/legion/extension/every_actor_requires_time.rb', line 29

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

  superclass = node.parent_class
  return unless superclass && interval_base?(superclass)
  return if calls_time?(node)

  add_offense(node.identifier)
end