Sha256: 44b42dbdcd95f4e84a25b644baea9ce55464bfc31de496bca0068d59f636f5de
Contents?: true
Size: 870 Bytes
Versions: 4
Compression:
Stored size: 870 Bytes
Contents
# encoding: UTF-8 module Mojito::Controllers::Runtime module Path require 'cgi' def PATH(pattern, delimiter = %r{/|\z}) consume_path = proc do |pattern| if match = env['PATH_INFO'].match(%r<\A/*#{pattern}(?=#{delimiter})>) env['SCRIPT_NAME'] = match.to_s env['PATH_INFO'] = match.post_match request.locals.update match.names.inject({}) {|hash, name| hash[name.to_sym] = CGI.unescape(match[name]) ; hash } request.captures.push *(match.captures.collect {|c| CGI.unescape c }) true else false end end proc do if p = case pattern when String pattern.gsub(%r{/?:\?\w+}) {|name| "(?:/(?<#{name[2..-1]}>[^/]+?))?" }.gsub(%r{:\w+}) {|name| "(?<#{name[1..-1]}>[^/]+?)" } when Regexp pattern end instance_exec p, &consume_path else false end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems