Created
June 3, 2017 06:05
-
-
Save sushant12/cff595cf45089f12740bea26042e1c1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Todo | |
class Router | |
attr_reader :app | |
ROUTES = { | |
'/' => {'controller' => 'tasks', 'action' => 'index'}, | |
'/save_task' => {'controller' => 'tasks', 'action' => 'save'}, | |
'/edit' => {'controller' => 'tasks', 'action' => 'edit'}, | |
'/update' => {'controller' => 'tasks', 'action' => 'update'}, | |
'/delete' => {'controller' => 'tasks', 'action' => 'destroy'} | |
} | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
if (mapping = ROUTES[env['PATH_INFO']]) | |
env.merge!(mapping) | |
app.call(env) | |
else | |
Rack::Response.new('Not found', 404) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment