Class: Mousevc::Router
- Inherits:
-
Object
- Object
- Mousevc::Router
- Defined in:
- lib/mousevc/router.rb
Overview
Router routes requests to the controller method. Instantiated by the Mousevc::App class.
Instance Attribute Summary collapse
-
#action ⇒ Symbol
The action sent to the controller method.
-
#controller ⇒ String
The instance of the current controller.
-
#model ⇒ String, Symbol
The instance of the current model.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Router
constructor
Creates a new
Mousevc::Routerinstance. -
#route ⇒ Object
Routes by:.
Constructor Details
#initialize(options = {}) ⇒ Router
Creates a new Mousevc::Router instance
47 48 49 50 51 52 |
# File 'lib/mousevc/router.rb', line 47 def initialize(={}) @controller = [:controller] ? [:controller] : 'Controller' @model = [:model] ? [:model] : 'Model' @action = [:action] ? [:action] : :hello_mousevc @views = [:views] end |
Instance Attribute Details
#action ⇒ Symbol
Set this variable to the symbol name of the method to call on the next controller
Returns the action sent to the controller method.
36 37 38 |
# File 'lib/mousevc/router.rb', line 36 def action @action end |
#controller ⇒ String
Set this variable to the string name of the controller class to be instantiated upon the next application loop
Returns the instance of the current controller.
19 20 21 |
# File 'lib/mousevc/router.rb', line 19 def controller @controller end |
#model ⇒ String, Symbol
Set this variable to the string name of the model class to be instantiated upon the next application loop
Can be used to retrieve a model from the Mousevc::Persistence class when set to a symbol.
Returns the instance of the current model.
28 29 30 |
# File 'lib/mousevc/router.rb', line 28 def model @model end |
Instance Method Details
#route ⇒ Object
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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# 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 |