Sha256: a4cbfb5057bbb0d6cd59243ac11f32b429b1a3df28119c9ea9543ceb878e8173

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.0 lib/mojito/matchers/path.rb