Class: Celluloid::SystemEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid/system_events.rb

Overview

High-priority internal system events

Defined Under Namespace

Classes: LinkingEvent

Constant Summary collapse

@@system_events =
{}

Class Method Summary collapse

Class Method Details

.handle(type) ⇒ Object


16
17
18
# File 'lib/celluloid/system_events.rb', line 16

def handle(type)
  @@system_events[type]
end

.handler(&block) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/celluloid/system_events.rb', line 20

def handler(&block)
  fail ArgumentError, "SystemEvent handlers must be defined with a block." unless block
  method = begin
    handler = name
              .split("::").last
              .gsub(/([A-Z]+)([A-Z][a-z])/, "\1_\2")
              .gsub(/([a-z\d])([A-Z])/, "\1_\2")
              .tr("-", "_")
              .downcase
    :"handle_#{handler}"
  end
  Actor.send(:define_method, method, &block)
  @@system_events[self] = method
end