Skip to content

Instantly share code, notes, and snippets.

@sushant12
Created June 3, 2017 06:05
Show Gist options
  • Save sushant12/cff595cf45089f12740bea26042e1c1c to your computer and use it in GitHub Desktop.
Save sushant12/cff595cf45089f12740bea26042e1c1c to your computer and use it in GitHub Desktop.
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