Class: PureMVC::Notifier
- Inherits:
-
Object
- Object
- PureMVC::Notifier
- Defined in:
- src/patterns/observer/notifier.rb
Overview
A base INotifier implementation.
MacroCommand, SimpleCommand, Mediator, and Proxy all need to send Notifications.
The INotifier interface provides a common method called send_notification that relieves implementation code of the necessity to actually construct Notifications.
The Notifier class, which all the above-mentioned classes extend, provides an initialized reference to the Facade Multiton, which is required for the convenience method for sending Notifications. It also eases implementation, as these classes have frequent Facade interactions and usually require access to it anyway.
NOTE: In the MultiCore version of the framework, there is one caveat: notifiers cannot send notifications or reach the facade until they have a valid multiton_key.
The multiton_key is set:
-
on a
SimpleCommandwhen it is executed by the <code>Controller<c/ode> -
on a
Mediatorwhen registered with theView -
on a
Proxywhen registered with theModel
Direct Known Subclasses
Constant Summary collapse
- MULTITON_MSG =
Message Constants
'multitonKey for this Notifier not yet initialized!'
Instance Attribute Summary collapse
- #multiton_key ⇒ Object readonly
Instance Method Summary collapse
-
#facade ⇒ IFacade
Return the Multiton Facade instance.
-
#initialize_notifier(key) ⇒ Object
Initialize this INotifier instance.
-
#send_notification(name, body = nil, type = nil) ⇒ Object
Create and send an INotification.
Instance Attribute Details
#multiton_key ⇒ Object (readonly)
46 47 48 |
# File 'src/patterns/observer/notifier.rb', line 46 def multiton_key @multiton_key end |
Instance Method Details
#facade ⇒ IFacade
Return the Multiton Facade instance
81 82 83 84 85 |
# File 'src/patterns/observer/notifier.rb', line 81 def facade raise MULTITON_MSG if @multiton_key.nil? Facade.get_instance(@multiton_key) { |key| Facade.new(key) } end |
#initialize_notifier(key) ⇒ Object
Initialize this INotifier instance.
This is how a Notifier receives its multiton_key. Any calls to send_notification or attempts to access the facade will fail until this method has been called.
Subclasses such as Mediator, Command, or Proxy may override this method if they need to send notifications or access the Facade instance as early as possible. However, note that the Facade cannot be accessed within the constructor of these classes, because initialize_notifier will not yet have been called at that point.
61 62 63 |
# File 'src/patterns/observer/notifier.rb', line 61 def initialize_notifier(key) @multiton_key = key end |
#send_notification(name, body = nil, type = nil) ⇒ Object
Create and send an INotification.
This method eliminates the need to manually construct INotification instances in your implementation code.
73 74 75 |
# File 'src/patterns/observer/notifier.rb', line 73 def send_notification(name, body = nil, type = nil) facade.send_notification(name, body, type) end |