http_router 0.8.11 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,45 +0,0 @@
1
- class HttpRouter
2
- class Node
3
- class Destination < Node
4
- attr_reader :blk, :allow_partial, :param_names
5
-
6
- def initialize(router, parent, blk, allow_partial)
7
- @blk, @allow_partial = blk, allow_partial
8
- super(router, parent)
9
- end
10
-
11
- def usable?(other)
12
- other.class == self.class && other.allow_partial == allow_partial && other.blk == blk
13
- end
14
-
15
- def to_code
16
- path = blk
17
- path_ivar = :"@path_#{router.next_counter}"
18
- inject_root_ivar(path_ivar, blk)
19
- "#{"if request.path_finished?" unless @allow_partial}
20
- catch(:pass) do
21
- #{"if request.path.size == 1 && request.path.first == '' && (request.rack_request.head? || request.rack_request.get?) && request.rack_request.path_info[-1] == ?/
22
- response = ::Rack::Response.new
23
- response.redirect(request.rack_request.path_info[0, request.rack_request.path_info.size - 1], 302)
24
- throw :success, response.finish
25
- end" if @router.redirect_trailing_slash?}
26
-
27
- #{"if request.path.empty?#{" or (request.path.size == 1 and request.path.first == '')" if @router.ignore_trailing_slash?}" unless @allow_partial}
28
- if request.perform_call
29
- env = request.rack_request.dup.env
30
- env['router.request'] = request
31
- env['router.params'] ||= {}
32
- #{"env['router.params'].merge!(Hash[#{path.param_names.inspect}.zip(request.params)])" if path.dynamic?}
33
- #{@allow_partial ? "router.rewrite_partial_path_info(env, request)" : "router.rewrite_path_info(env, request)" }
34
- response = @router.process_destination_path(#{path_ivar}, env)
35
- router.pass_on_response(response) ? throw(:pass) : throw(:success, response)
36
- else
37
- throw :success, Response.new(request, #{path_ivar})
38
- end
39
- #{"end" unless @allow_partial}
40
- end
41
- #{"end" unless @allow_partial}"
42
- end
43
- end
44
- end
45
- end
@@ -1,58 +0,0 @@
1
- require 'uri'
2
- class HttpRouter
3
- class Path
4
- attr_reader :route, :param_names, :dynamic
5
- alias_method :dynamic?, :dynamic
6
- def initialize(route, path, param_names = [])
7
- @route, @path, @param_names, @dynamic = route, path, param_names, !param_names.empty?
8
- duplicate_param_names = param_names.dup.uniq!
9
- raise AmbiguousVariableException, "You have duplicate variable name present: #{duplicate_param_names.join(', ')}" if duplicate_param_names
10
- if path.respond_to?(:split)
11
- regex_parts = path.split(/([:\*][a-zA-Z0-9_]+)/)
12
- @path_validation_regex, code = '', ''
13
- regex_parts.each_with_index{ |part, index|
14
- new_part = case part[0]
15
- when ?:, ?*
16
- if index != 0 && regex_parts[index - 1][-1] == ?\\
17
- @path_validation_regex << Regexp.quote(part)
18
- code << part
19
- else
20
- @path_validation_regex << (route.matches_with[part[1, part.size].to_sym] || '.*?').to_s
21
- code << "\#{args.shift || (options && options.delete(:#{part[1, part.size]})) || raise(MissingParameterException, \"missing parameter :#{part[1, part.size]}\")}"
22
- end
23
- else
24
- @path_validation_regex << Regexp.quote(part)
25
- code << part
26
- end
27
- new_part
28
- }
29
- @path_validation_regex = Regexp.new("^#{@path_validation_regex}$")
30
- instance_eval <<-EOT, __FILE__, __LINE__ + 1
31
- def raw_url(args,options)
32
- \"#{code}\"
33
- end
34
- EOT
35
- end
36
- end
37
-
38
- def hashify_params(params)
39
- @dynamic && params ? Hash[param_names.zip(params)] : {}
40
- end
41
-
42
- def url(args, options)
43
- path = raw_url(args, options)
44
- raise InvalidRouteException if path !~ @path_validation_regex
45
- raise TooManyParametersException unless args.empty?
46
- [URI.escape(path), options]
47
- end
48
-
49
- def original_path
50
- @path
51
- end
52
-
53
- private
54
- def raw_url(args, options)
55
- raise InvalidRouteException
56
- end
57
- end
58
- end