class Crimson::NotificationBus

Attributes

notification_handlers[R]

Public Class Methods

new() click to toggle source
# File lib/crimson/notification_bus.rb, line 9
def initialize
  @notification_handlers = Hashie::Mash.new
end

Public Instance Methods

notify(message) click to toggle source
# File lib/crimson/notification_bus.rb, line 27
def notify(message)
  unless notification_handlers.key?(message.id)
    raise ArgumentError, "[NotificationBus] Trying to notify unregistered '#{message.id}'."
  end

  notification_handlers[message.id].call(message)
end
register(object) click to toggle source
# File lib/crimson/notification_bus.rb, line 13
def register(object)
  raise ArgumentError unless object.is_a?(Crimson::Object)
  raise ArgumentError if notification_handlers.key?(object.id)

  notification_handlers[object.id] = object.method(:on_event)
end
unregister(object) click to toggle source
# File lib/crimson/notification_bus.rb, line 20
def unregister(object)
  raise ArgumentError unless object.is_a?(Crimson::Object)
  raise ArgumentError unless notification_handlers.key?(object.id)

  notification_handlers.delete(object.id)
end