16 Proc.new { |*args| args.shift.__send__(self, *args) }
22 self.inject({}) { |h, (k, v)| h[k] = v; h }
26 Proc.new { |*args| args.shift.send(self[0], args + self[1..-1]) }
33 find { |e| result = block[e] and break result }
42 @request_types ||= [:get, :put, :post, :delete]
46 @routes ||= Hash.new do |hash, key|
47 hash[key] = [] if request_types.include?(key)
51 def determine_event(verb, path)
52 routes[verb].eject { |r| r.match(path) }
57 URI_CHAR = '[^/?:,&#]'.freeze unless defined?(URI_CHAR)
58 PARAM = /:(#{URI_CHAR}+)/.freeze unless defined?(PARAM)
60 attr_reader :block, :path
62 def initialize(path, &b)
63 @path, @block = path, b
65 regex = path.to_s.gsub(PARAM) do
66 @param_keys << $1.intern
69 @pattern = /^#{regex}$/
70 @struct = Struct.new(:block, :params)
74 return nil unless path =~ @pattern
75 params = @param_keys.zip($~.captures.map(&:from_param)).to_hash
76 @struct.new(@block, params)