Skip to content

Commit

Permalink
document custom route matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed Feb 21, 2011
1 parent f733dd7 commit 7ec4039
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README.rdoc
Expand Up @@ -151,6 +151,47 @@ That way we can for instance easily implement a streaming example:

get('/') { Stream.new }

=== Custom Route Matchers

As shown above, Sinatra ships with built-in support for using String patterns
and regular expressions as route matches. However, it does not stop there. You
can easily define your own matchers:

class AllButPattern
Match = Struct.new(:captures)

def initialize(except)
@except = except
@caputres = Match.new([])
end

def match(str)
@caputres unless @except === str
end
end

def all_but(pattern)
AllButPattern.new(pattern)
end

get all_but("/index") do
# ...
end

Note that the above example might be over-engineered, as it can also be
expressed as:

get // do
pass if request.path_info == "/index"
# ...
end

Or, using negative look ahead:

get %r{^(?!/index$)} do
# ...
end

== Static Files

Static files are served from the <tt>./public</tt> directory. You can specify
Expand Down

0 comments on commit 7ec4039

Please sign in to comment.