Class Controller
In: src/org/puremvc/ruby/core/controller.rb
Parent: Object

In PureMVC, the Controller class assumes these responsibilities:

  • Remembering which Command is intended to handle which Notification.
  • Registering itself as an Observer with the View for each Notification that it has an Command mapping for.
  • Creating instances of the proper Command to handle a given Notification when notified by the View.
  • Calling the Command‘s execute method, passing in the Notification.

Your application must register any Commands with the Controller.

The simplest way is to subclass Facade, and use its initializeController method to add your registrations.

Methods

Included Modules

Singleton

Attributes

command_map  [RW] 
view  [RW] 

Public Class methods

This Controller implementation is a Singleton, so you can not call the constructor directly, but instead call the static Singleton Factory method Controller.instance

Public Instance methods

If a Command has previously been registered to handle a given Notification, then it is executed

Check if a command is registered for a given Notification

Initialize the Singleton Controller instance.

Called Automatically by the construcor.

Note that if you are using a subclass of View in your application, you should also subclass Controller and override the initialize_controller method in the following way:

<tt>

  def initialize_controller
     @view = MyView.instance
  end

</tt>

Register a particular Command class as the handler for a particular Notification.

If a Command has already been registered to handle Notification‘s with this name, it is no longer user, the new Command is used instead.

The Observer for the new Command is only created if this is the first time a Command has been registered for this Notification name.

Remove a previously registered Command for a given Notification

[Validate]