Last active
December 12, 2015 04:18
-
-
Save jamiehodge/4713086 to your computer and use it in GitHub Desktop.
Sinatra Journey
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
require 'journey' | |
require 'forwardable' | |
class Router | |
extend Forwardable | |
def_delegator :router, :call | |
def_delegator :formatter, :generate | |
def add_route(app, path, conditions={}, defaults={}, name) | |
routes.add_route( | |
app, | |
pattern(expression(path)), | |
conditions, | |
defaults, | |
name | |
) | |
end | |
private | |
def pattern(expr) | |
Journey::Path::Pattern.new(expr) | |
end | |
def expression(path) | |
Journey::Router::Strexp.new(path, {}, ['/', '.', '?'], false) | |
end | |
def routes | |
@routes ||= Journey::Routes.new | |
end | |
def router | |
@router ||= | |
Journey::Router.new(routes, {parameters_key: 'rack.request.query_hash'}) | |
end | |
def formatter | |
@formatter ||= Journey::Formatter.new(routes) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment