rack-mount 0.0.1 → 0.6.13
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.
- data/README.rdoc +12 -4
- data/lib/rack/mount/analysis/frequency.rb +15 -6
- data/lib/rack/mount/analysis/histogram.rb +55 -6
- data/lib/rack/mount/analysis/splitting.rb +85 -71
- data/lib/rack/mount/code_generation.rb +117 -0
- data/lib/rack/mount/generatable_regexp.rb +95 -48
- data/lib/rack/mount/multimap.rb +2 -43
- data/lib/rack/mount/prefix.rb +12 -7
- data/lib/rack/mount/regexp_with_named_groups.rb +27 -7
- data/lib/rack/mount/route.rb +79 -18
- data/lib/rack/mount/route_set.rb +330 -22
- data/lib/rack/mount/strexp/parser.rb +0 -0
- data/lib/rack/mount/strexp/parser.y +34 -0
- data/lib/rack/mount/strexp/tokenizer.rb +83 -0
- data/lib/rack/mount/strexp/tokenizer.rex +12 -0
- data/lib/rack/mount/strexp.rb +54 -79
- data/lib/rack/mount/utils.rb +65 -174
- data/lib/rack/mount/vendor/multimap/multimap.rb +142 -39
- data/lib/rack/mount/vendor/multimap/multiset.rb +33 -1
- data/lib/rack/mount/vendor/multimap/nested_multimap.rb +18 -16
- data/lib/rack/mount/vendor/regin/regin/alternation.rb +40 -0
- data/lib/rack/mount/vendor/regin/regin/anchor.rb +4 -0
- data/lib/rack/mount/vendor/regin/regin/atom.rb +54 -0
- data/lib/rack/mount/vendor/regin/regin/character.rb +51 -0
- data/lib/rack/mount/vendor/regin/regin/character_class.rb +50 -0
- data/lib/rack/mount/vendor/regin/regin/collection.rb +77 -0
- data/lib/rack/mount/vendor/regin/regin/expression.rb +126 -0
- data/lib/rack/mount/vendor/regin/regin/group.rb +85 -0
- data/lib/rack/mount/vendor/regin/regin/options.rb +55 -0
- data/lib/rack/mount/vendor/regin/regin/parser.rb +521 -0
- data/lib/rack/mount/vendor/regin/regin/tokenizer.rb +0 -0
- data/lib/rack/mount/vendor/regin/regin/version.rb +3 -0
- data/lib/rack/mount/vendor/regin/regin.rb +75 -0
- data/lib/rack/mount/version.rb +3 -0
- data/lib/rack/mount.rb +13 -16
- metadata +73 -29
- data/lib/rack/mount/const.rb +0 -45
- data/lib/rack/mount/exceptions.rb +0 -3
- data/lib/rack/mount/generation/route.rb +0 -57
- data/lib/rack/mount/generation/route_set.rb +0 -163
- data/lib/rack/mount/meta_method.rb +0 -104
- data/lib/rack/mount/mixover.rb +0 -47
- data/lib/rack/mount/recognition/code_generation.rb +0 -99
- data/lib/rack/mount/recognition/route.rb +0 -59
- data/lib/rack/mount/recognition/route_set.rb +0 -88
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
require 'rack/mount/prefix'
|
|
2
|
-
|
|
3
|
-
module Rack::Mount
|
|
4
|
-
module Recognition
|
|
5
|
-
module Route #:nodoc:
|
|
6
|
-
attr_reader :named_captures
|
|
7
|
-
|
|
8
|
-
def initialize(*args)
|
|
9
|
-
super
|
|
10
|
-
|
|
11
|
-
# TODO: Don't explict check for :path_info condition
|
|
12
|
-
if @conditions.has_key?(:path_info) &&
|
|
13
|
-
!Utils.regexp_anchored?(@conditions[:path_info])
|
|
14
|
-
@app = Prefix.new(@app)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
@named_captures = {}
|
|
18
|
-
@conditions.map { |method, condition|
|
|
19
|
-
@named_captures[method] = condition.named_captures.inject({}) { |named_captures, (k, v)|
|
|
20
|
-
named_captures[k.to_sym] = v.last - 1
|
|
21
|
-
named_captures
|
|
22
|
-
}.freeze
|
|
23
|
-
}
|
|
24
|
-
@named_captures.freeze
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def call(req)
|
|
28
|
-
env = req.env
|
|
29
|
-
|
|
30
|
-
routing_args = @defaults.dup
|
|
31
|
-
if @conditions.all? { |method, condition|
|
|
32
|
-
value = req.send(method)
|
|
33
|
-
if m = value.match(condition)
|
|
34
|
-
matches = m.captures
|
|
35
|
-
@named_captures[method].each { |k, i|
|
|
36
|
-
if v = matches[i]
|
|
37
|
-
# TODO: We only want to unescape params from
|
|
38
|
-
# uri related methods
|
|
39
|
-
routing_args[k] = Utils.unescape_uri(v)
|
|
40
|
-
end
|
|
41
|
-
}
|
|
42
|
-
# TODO: Don't explict check for :path_info condition
|
|
43
|
-
if method == :path_info && !Utils.regexp_anchored?(condition)
|
|
44
|
-
env[Prefix::KEY] = m.to_s
|
|
45
|
-
end
|
|
46
|
-
true
|
|
47
|
-
else
|
|
48
|
-
false
|
|
49
|
-
end
|
|
50
|
-
}
|
|
51
|
-
env[@set.parameters_key] = routing_args
|
|
52
|
-
@app.call(env)
|
|
53
|
-
else
|
|
54
|
-
Const::EXPECTATION_FAILED_RESPONSE
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
require 'rack/mount/utils'
|
|
2
|
-
|
|
3
|
-
module Rack::Mount
|
|
4
|
-
module Recognition
|
|
5
|
-
module RouteSet
|
|
6
|
-
attr_reader :parameters_key
|
|
7
|
-
|
|
8
|
-
# Adds recognition related concerns to RouteSet.new.
|
|
9
|
-
def initialize(options = {})
|
|
10
|
-
@parameters_key = options.delete(:parameters_key) || Const::RACK_ROUTING_ARGS
|
|
11
|
-
@parameters_key.freeze
|
|
12
|
-
@recognition_key_analyzer = Analysis::Frequency.new_with_module(Analysis::Splitting)
|
|
13
|
-
|
|
14
|
-
super
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Adds recognition aspects to RouteSet#add_route.
|
|
18
|
-
def add_route(*args)
|
|
19
|
-
route = super
|
|
20
|
-
@recognition_key_analyzer << route.conditions
|
|
21
|
-
route
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# Rack compatible recognition and dispatching method. Routes are
|
|
25
|
-
# tried until one returns a non-catch status code. If no routes
|
|
26
|
-
# match, the catch status code is returned.
|
|
27
|
-
#
|
|
28
|
-
# This method can only be invoked after the RouteSet has been
|
|
29
|
-
# finalized.
|
|
30
|
-
def call(env)
|
|
31
|
-
raise 'route set not finalized' unless @recognition_graph
|
|
32
|
-
|
|
33
|
-
set_expectation = env[Const::EXPECT] != Const::CONTINUE
|
|
34
|
-
env[Const::EXPECT] = Const::CONTINUE if set_expectation
|
|
35
|
-
|
|
36
|
-
env[Const::PATH_INFO] = Utils.normalize_path(env[Const::PATH_INFO])
|
|
37
|
-
|
|
38
|
-
cache = {}
|
|
39
|
-
req = @request_class.new(env)
|
|
40
|
-
keys = @recognition_keys.map { |key|
|
|
41
|
-
if key.is_a?(Array)
|
|
42
|
-
key.call(cache, req)
|
|
43
|
-
else
|
|
44
|
-
req.send(key)
|
|
45
|
-
end
|
|
46
|
-
}
|
|
47
|
-
@recognition_graph[*keys].each do |route|
|
|
48
|
-
result = route.call(req)
|
|
49
|
-
return result unless result[0].to_i == 417
|
|
50
|
-
end
|
|
51
|
-
set_expectation ? Const::NOT_FOUND_RESPONSE : Const::EXPECTATION_FAILED_RESPONSE
|
|
52
|
-
ensure
|
|
53
|
-
env.delete(Const::EXPECT) if set_expectation
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def rehash #:nodoc:
|
|
57
|
-
@recognition_keys = build_recognition_keys
|
|
58
|
-
@recognition_graph = build_recognition_graph
|
|
59
|
-
|
|
60
|
-
super
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def valid_conditions #:nodoc:
|
|
64
|
-
@valid_conditions ||= begin
|
|
65
|
-
conditions = @request_class.instance_methods(false)
|
|
66
|
-
conditions.map! { |m| m.to_sym }
|
|
67
|
-
conditions.freeze
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
private
|
|
72
|
-
def expire!
|
|
73
|
-
@recognition_keys = @recognition_graph = nil
|
|
74
|
-
super
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def build_recognition_graph
|
|
78
|
-
build_nested_route_set(@recognition_keys) { |k, i|
|
|
79
|
-
@recognition_key_analyzer.possible_keys[i][k]
|
|
80
|
-
}
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def build_recognition_keys
|
|
84
|
-
@recognition_key_analyzer.report
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|