Class: Reloj::Route
- Inherits:
-
Object
- Object
- Reloj::Route
- Defined in:
- lib/reloj/core/router.rb
Instance Attribute Summary collapse
-
#action_name ⇒ Object
readonly
Returns the value of attribute action_name.
-
#controller_class ⇒ Object
readonly
Returns the value of attribute controller_class.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#initialize(pattern, http_method, controller_class, action_name) ⇒ Route
constructor
A new instance of Route.
- #matches?(req) ⇒ Boolean
- #run(req, res, paths = []) ⇒ Object
Constructor Details
#initialize(pattern, http_method, controller_class, action_name) ⇒ Route
Returns a new instance of Route.
8 9 10 11 12 13 14 |
# File 'lib/reloj/core/router.rb', line 8 def initialize(pattern, http_method, controller_class, action_name) @pattern = pattern @http_method = http_method @controller_class = controller_class @action_name = action_name # save all helpers in the routes end |
Instance Attribute Details
#action_name ⇒ Object (readonly)
Returns the value of attribute action_name.
6 7 8 |
# File 'lib/reloj/core/router.rb', line 6 def action_name @action_name end |
#controller_class ⇒ Object (readonly)
Returns the value of attribute controller_class.
6 7 8 |
# File 'lib/reloj/core/router.rb', line 6 def controller_class @controller_class end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
6 7 8 |
# File 'lib/reloj/core/router.rb', line 6 def http_method @http_method end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
6 7 8 |
# File 'lib/reloj/core/router.rb', line 6 def pattern @pattern end |
Instance Method Details
#matches?(req) ⇒ Boolean
17 18 19 20 |
# File 'lib/reloj/core/router.rb', line 17 def matches?(req) req.request_method.downcase.to_sym == @http_method && @pattern.match(req.path) end |
#run(req, res, paths = []) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/reloj/core/router.rb', line 23 def run(req, res, paths = []) route_params = {} matches = @pattern.match(req.path) matches.names.each do |key| route_params[key] = matches[key] end #pass the methods to the controller class here @controller_class.new(req, res, route_params, paths).invoke_action(@action_name) end |