Sha256: 877b105790fed70c4d09aa8558f132cf9ec4e7054dd8bd77279dd8587b38f59e

Contents?: true

Size: 764 Bytes

Versions: 1

Compression:

Stored size: 764 Bytes

Contents

# encoding: UTF-8

module Mojito::Matchers
	
	module Path
		
		def PATH(pattern)
			consume_path = proc do |pattern|
				if match = env['PATH_INFO'].match(%r<\A/*#{pattern}(?=/|\z)>)
					env['SCRIPT_NAME'] = match.to_s
					env['PATH_INFO'] = match.post_match
					request.locals.update match.names.inject({}) {|hash, name| hash[name.to_sym] = match[name] ; hash }
					request.captures.push *match.captures
					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

1 entries across 1 versions & 1 rubygems

Version Path
mojito-0.1.1 lib/mojito/matchers/path.rb