Class: Buttons::Router
- Inherits:
-
Object
- Object
- Buttons::Router
- Defined in:
- lib/buttons/router.rb
Instance Method Summary collapse
- #add_route(http_method, path, params) ⇒ Object
-
#initialize ⇒ Router
constructor
A new instance of Router.
- #print_routes ⇒ Object
- #recognize(request) ⇒ Object
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
3 4 5 |
# File 'lib/buttons/router.rb', line 3 def initialize @routes = {} end |
Instance Method Details
#add_route(http_method, path, params) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/buttons/router.rb', line 7 def add_route(http_method, path, params) http_method = http_method.to_s.downcase @routes[http_method] ||= {} @routes[http_method][path] = params end |
#print_routes ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/buttons/router.rb', line 20 def print_routes @routes.map do |http_method, routes| routes.map do |route, params| "%8s %s %s" % [http_method.upcase, route, params.inspect] end.join("\n") end.join("\n") end |
#recognize(request) ⇒ Object
14 15 16 17 18 |
# File 'lib/buttons/router.rb', line 14 def recognize(request) request_method = request.request_method.to_s.downcase @routes[request_method] && @routes[request_method][request.path] end |