Class: RuboCop::Cop::Legion::Extension::AbsorberMissingPattern

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

Overview

Detects absorber classes inside an ‘Absorbers` namespace that do not call the `pattern` DSL method. Without `pattern`, the absorber will not match any events and will be silently inactive.

Examples:

# bad
module Absorbers
  class Foo
    def absorb(event)
      process(event)
    end
  end
end

# good
module Absorbers
  class Foo
    pattern 'some.event.*'

    def absorb(event)
      process(event)
    end
  end
end

Constant Summary collapse

MSG =
'Absorber classes must call the `pattern` DSL method to match events.'

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



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

def on_class(node)
  return unless inside_absorbers_namespace?(node)
  return if calls_pattern?(node)

  add_offense(node.identifier)
end