Class: RuboCop::Cop::Legion::Extension::ActorEnabledSideEffects

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

Overview

Detects ‘def enabled?` methods inside actor classes. The `enabled?` method runs during extension loading before `delay` is honoured, so it must be cheap and side-effect-free (no network calls, mutex locks, or I/O).

Examples:

# bad — network call during boot
module Actor
  class Check < Every
    def enabled?
      Legion::Transport.connected?
    end
  end
end

# good — cheap Settings lookup
module Actor
  class Check < Every
    def enabled?
      !Legion::Settings[:check].nil?
    end
  end
end

Constant Summary collapse

MSG =
'`enabled?` runs during extension loading, before `delay`. ' \
'Keep it cheap and side-effect-free (no network calls, mutex locks, or I/O).'

Instance Method Summary collapse

Instance Method Details

#on_def(node) ⇒ Object



34
35
36
37
38
39
# File 'lib/rubocop/cop/legion/extension/actor_enabled_side_effects.rb', line 34

def on_def(node)
  return unless node.method_name == :enabled?
  return unless inside_actor_namespace?(node)

  add_offense(node)
end