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



19
20
21
# File 'lib/celluloid/system_events.rb', line 19

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

.handler(&block) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/celluloid/system_events.rb', line 23

def handler(&block)
  raise 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