class Mousevc::Router
Router
routes requests to the controller method. Instantiated by the Mousevc::App
class.
Attributes
@!attribute action
@note Set this variable to the symbol name of the method to call on the next controller
@return [Symbol] the action sent to the controller method
@!attribute controller
@note Set this variable to the string name of the controller class to be instantiated upon the next application loop
@return [String] the instance of the current controller
@!attribute model
@note Set this variable to the string name of the model class to be instantiated upon the next application loop @note Can be used to retrieve a model from the Mousevc::Persistence
class when set to a symbol.
@return [String, Symbol] the instance of the current model.
Public Class Methods
Creates a new Mousevc::Router
instance
@param options [Hash] expects the following keys:
- :controller => [String] name of default controller class - :model => [String] name of default model class - :action => [Symbol] method to call on default controller - :views => [String] relative path to views directory
# File lib/mousevc/router.rb, line 47 def initialize(options={}) @controller = options[:controller] ? options[:controller] : 'Controller' @model = options[:model] ? options[:model] : 'Model' @action = options[:action] ? options[:action] : :hello_mousevc @views = options[:views] end
Public Instance Methods
Routes by:
-
creating an instance of the current controller in the +@controller+ attribute
-
creating an instance of the current model in the +@model+ attribute
-
creating a new or finding the desired model
-
passing that controller that model instance, a view instance, and an instance of
self
-
sending the controller the current action in +@action+
# File lib/mousevc/router.rb, line 63 def route model = Persistence.get(@controller.to_sym) # TODO if reset, reset Persistence? model = Persistence.get(@model) if @model.is_a?(Symbol) unless model model = Mousevc.factory(@model).new Persistence.set(@controller.to_sym, model) end view = View.new(:dir => @views) controller = Mousevc.factory(@controller).new( :view => view, :model => model, :router => self ) controller.send(@action) end