Created
September 14, 2008 07:07
-
-
Save dyoder/10717 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
def call( request ) | |
capture = {} | |
path = extract_path( request ) | |
capture if @pattern.all? do | want | | |
case want | |
when true then path = [] | |
when String then want == path.pop | |
when Symbol then capture[ want ] = path.pop | |
when Regexp then want === path.pop | |
when Hash | |
key, value = want.to_a.first | |
case value | |
when true then | |
capture[ key ] = path.reverse | |
path = [] | |
when String, Symbol | |
got = path.pop | |
capture[ key ] = got ? got : want.to_s | |
when Regexp then | |
got = path.pop | |
capture[ key ] = got if value === got | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment