Class: Informator::Subscriber Private

Inherits:
Object
  • Object
show all
Defined in:
lib/informator/subscriber.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class Subscriber wraps the [#object] along with its [#callback] method to receive event notifications.

Examples:

The method [#notify] sends event to the [#object] via [#callback]

object     = Struct.new(:event).new
subscriber = Subscriber.new object, :event=
subscriber.frozen? # => true

event  = Informator::Event.new :success
# => #<Event @type=:success @attributes={} @messages=[]>

subscriber.notify event
object.event
# => #<Event @type=:success @attributes={} @messages=[]>

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#callbackSymbol (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the name of the object methods to listen to events.

Returns:

  • (Symbol)

    the name of the object methods to listen to events



36
37
38
# File 'lib/informator/subscriber.rb', line 36

def callback
  @callback
end

#objectObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the object to send events to.

Returns:

  • (Object)

    the object to send events to



30
31
32
# File 'lib/informator/subscriber.rb', line 30

def object
  @object
end

Class Method Details

.initialize(object, callback = :receive) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
51
52
# File 'lib/informator/subscriber.rb', line 48

def initialize(object, callback = :receive)
  @object   = object
  @callback = callback.to_sym
  IceNine.deep_freeze(self)
end

.new(object, callback) ⇒ Informator::Subscriber

Builds the subscriber for given object and callback

Parameters:

  • object (Object)
  • callback (#to_sym)

    (:receive)

Returns:



# File 'lib/informator/subscriber.rb', line 38


.notify(event) ⇒ Informator::Event

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sends the event to the subscriber object via its callback

Parameters:

Returns:



60
61
62
63
64
# File 'lib/informator/subscriber.rb', line 60

def notify(event)
  object.public_send callback, event

  event
end