Ravn::Actor::MessageHandling::

InstanceMethods module

Instance methods added to Classes that extend MessageHandling.

Public Instance Methods

filter_down( message )

Call the message handler that has the longest match against the given message‘s type and then super to the extended class’s implementation.

# File lib/ravn/actor/message_handling.rb, line 96
def filter_down( message )
        message.audit {}
        if (handler = self.lookup_handler( message.type ))
                Loggability[ Ravn::Actor::MessageHandling ].
                        debug "Found handler for %s event: %p" % [ message.type, handler ]

                # :FIXME: I think this should be returning to prevent double-processing messages
                handler.call( message )
        end

        # :nocov:
        super if defined?( super )
        # :nocov:
end
lookup_handler( message_type )

Look up the name of the most-specific handler for messages of the given message_type and return it as a call-able. :TODO: Memoize to avoid the method lookup

# File lib/ravn/actor/message_handling.rb, line 115
def lookup_handler( message_type )
        handler = self.message_handlers.longest_prefix_value( message_type ) or return nil
        return self.public_method( handler )
end
message_handlers()

Delegate per-instance message handlers to the per-class ones by default.

# File lib/ravn/actor/message_handling.rb, line 122
def message_handlers
        return self.class.message_handlers
end