Class ActionMessenger::Messenger
In: lib/action_messenger/messenger.rb
Parent: Object

Represents a single instant messenger.

Methods

Attributes

config  [R]  The configuration used to load this messenger.

Public Class methods

Initialises the messenger. At the moment this class doesn‘t do anything with the config except store it into an attribute.

[Source]

    # File lib/action_messenger/messenger.rb, line 11
11:     def initialize(config_hash = {})
12:       @config = config_hash
13:       @message_handlers = []
14:     end

Resolves any object into a Messenger. If the object itself is a Messenger, the object itself is returned. Otherwise, it is converted to a string and that string is used to look it up in the registry.

[Source]

    # File lib/action_messenger/messenger.rb, line 31
31:     def self.resolve(messenger)
32:       if messenger.is_a?(Messenger)
33:         messenger
34:       else
35:         MessengerRegistry.find_by_name(messenger.to_s)
36:       end
37:     end

Public Instance methods

Adds a message handler which will be called for any incoming messages.

[Source]

    # File lib/action_messenger/messenger.rb, line 17
17:     def add_message_handler(&block)
18:       @message_handlers << block
19:     end

Called by subclasses when a message is received.

[Source]

    # File lib/action_messenger/messenger.rb, line 22
22:     def message_received(message)
23:       @message_handlers.each do |block|
24:         block.call(message)
25:       end
26:     end

Shuts down this messenger.

This implementation does nothing and is here for the convenience of subclasses that don‘t need special shutdown code.

[Source]

    # File lib/action_messenger/messenger.rb, line 43
43:     def shutdown
44:     end

[Validate]