lib/celluloid/system_events.rb in celluloid-0.18.0.pre vs lib/celluloid/system_events.rb in celluloid-0.18.0.pre2
- old
+ new
@@ -3,11 +3,14 @@
# Handle high-priority system event messages
def handle_system_event(event)
if handler = SystemEvent.handle(event.class)
send(handler, event)
else
+ # !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
+ # rubocop:disable Style/GlobalVars
Internals::Logger.debug "Discarded message (unhandled): #{message}" if $CELLULOID_DEBUG
+ # rubocop:enable Style/GlobalVars
end
end
end
# High-priority internal system events
class SystemEvent
@@ -16,11 +19,11 @@
def handle(type)
@@system_events[type]
end
def handler(&block)
- fail ArgumentError, "SystemEvent handlers must be defined with a block." unless 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")
@@ -36,11 +39,11 @@
class LinkingEvent < SystemEvent
# Shared initializer for LinkingRequest and LinkingResponse
def initialize(actor, type)
@actor = actor
@type = type.to_sym
- fail ArgumentError, "type must be link or unlink" unless [:link, :unlink].include?(@type)
+ raise ArgumentError, "type must be link or unlink" unless %i[link unlink].include?(@type)
end
end
end
# Request to link with another actor
@@ -85,21 +88,25 @@
class NamingRequest < SystemEvent
attr_reader :name
handler do |event|
@name = event.name
+
+ # !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
+ # rubocop:disable Style/GlobalVars
Celluloid::Probe.actor_named(self) if $CELLULOID_MONITORING
+ # rubocop:enable Style/GlobalVars
end
def initialize(name)
@name = name
end
end
# Request for an actor to terminate
class TerminationRequest < SystemEvent
- handler do |event|
+ handler do |_event|
terminate
end
end
# Signal a condition
@@ -108,12 +115,10 @@
@task = task
@value = value
end
attr_reader :task, :value
- handler do |event|
- event.call
- end
+ handler(&:call)
def call
@task.resume(@value)
end
end