Module: Easyop::Plugins::EventHandlers::ClassMethods

Defined in:
lib/easyop/plugins/event_handlers.rb

Instance Method Summary collapse

Instance Method Details

#_event_handler_registrationsObject



70
71
72
# File 'lib/easyop/plugins/event_handlers.rb', line 70

def _event_handler_registrations
  @_event_handler_registrations ||= []
end

#on(pattern, async: false, **options) ⇒ Object

Subscribe this operation to events matching pattern.

Registration happens at class-load time and is bound to the bus that is active when the class is evaluated. Configure the bus before loading handler classes (e.g. in a Rails initializer that runs before autoloading).

Parameters:

  • pattern (String, Regexp)

    event name or glob

  • async (Boolean) (defaults to: false)

    enqueue via call_async (requires Async plugin)

  • options (Hash)

    e.g. queue: “low” (overrides Async default)



58
59
60
61
62
63
64
65
66
67
# File 'lib/easyop/plugins/event_handlers.rb', line 58

def on(pattern, async: false, **options)
  _event_handler_registrations << { pattern: pattern, async: async, options: options }

  Easyop::Events::Registry.register_handler(
    pattern:       pattern,
    handler_class: self,
    async:         async,
    **options
  )
end