Class: WisperNext::Publisher

Inherits:
Module
  • Object
show all
Defined in:
lib/wisper_next/publisher.rb,
lib/wisper_next/publisher/callable_adapter.rb

Overview

Extension to provide objects with subscription and publishing capabilties

class PromoteUser

include Wisper.publisher

def call
  # ...
  broadcast(:user_promoted, user_id: user.id, ts: Time.now)
end

end

class NotifyUserOfPromotion

def on_event(name, payload)
  puts "#{name} => #{payload.inspect}"
end

end

command = PromoteUser.new command.subscribe(NotifyUserOfPromotion.new) command.call

Defined Under Namespace

Modules: Methods Classes: CallableAdapter

Constant Summary collapse

ListenerAlreadyRegisteredError =

Exception raised when a listener is already subscribed

Class.new(StandardError) do
  # @api private
  def initialize(listener)
    super("listener #{listener.inspect} is already subscribed")
  end
end
NoEventHandlerError =

Exception raised when a listener does not have an #on_event method

Class.new(ArgumentError) do
  # @api private
  def initialize(listener)
    super("listener #{listener.inspect} does not have an #on_event method")
  end
end

Instance Method Summary collapse

Instance Method Details

#included(descendant) ⇒ Object



27
28
29
30
# File 'lib/wisper_next/publisher.rb', line 27

def included(descendant)
  super
  descendant.send(:include, Methods)
end