rack-mount 0.3.3 → 0.4.0
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/lib/rack/mount/analysis/frequency.rb +4 -0
- data/lib/rack/mount/generation/route_set.rb +1 -0
- data/lib/rack/mount/recognition/code_generation.rb +19 -4
- data/lib/rack/mount/recognition/route_set.rb +7 -17
- data/lib/rack/mount/route.rb +1 -11
- data/lib/rack/mount/route_set.rb +52 -1
- data/lib/rack/mount/strexp/parser.rb +1 -0
- data/lib/rack/mount/vendor/multimap/multimap.rb +26 -0
- data/lib/rack/mount/vendor/multimap/multiset.rb +23 -0
- data/lib/rack/mount/vendor/reginald/reginald/tokenizer.rb +2 -8
- metadata +2 -2
@@ -1,6 +1,11 @@
|
|
1
1
|
module Rack::Mount
|
2
2
|
module Recognition
|
3
3
|
module CodeGeneration #:nodoc:
|
4
|
+
def initialize(*args)
|
5
|
+
@optimized_recognize_defined = false
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
4
9
|
def _expired_recognize(env) #:nodoc:
|
5
10
|
raise 'route set not finalized'
|
6
11
|
end
|
@@ -11,11 +16,19 @@ module Rack::Mount
|
|
11
16
|
end
|
12
17
|
|
13
18
|
private
|
19
|
+
def instance_variables_to_serialize
|
20
|
+
super - [:@optimized_recognize_defined]
|
21
|
+
end
|
22
|
+
|
14
23
|
def expire!
|
15
|
-
|
24
|
+
if @optimized_recognize_defined
|
25
|
+
remove_metaclass_method :recognize
|
26
|
+
|
27
|
+
class << self
|
28
|
+
alias_method :recognize, :_expired_recognize
|
29
|
+
end
|
16
30
|
|
17
|
-
|
18
|
-
alias_method :recognize, :_expired_recognize
|
31
|
+
@optimized_recognize_defined = false
|
19
32
|
end
|
20
33
|
|
21
34
|
super
|
@@ -64,10 +77,12 @@ module Rack::Mount
|
|
64
77
|
end
|
65
78
|
}.join(', ')
|
66
79
|
|
80
|
+
@optimized_recognize_defined = true
|
81
|
+
|
67
82
|
remove_metaclass_method :recognize
|
68
83
|
|
69
84
|
instance_eval(<<-RUBY, __FILE__, __LINE__)
|
70
|
-
def recognize(obj
|
85
|
+
def recognize(obj)
|
71
86
|
cache = {}
|
72
87
|
container = @recognition_graph[#{keys}]
|
73
88
|
optimize_container_iterator(container) unless container.respond_to?(:optimized_each)
|
@@ -45,7 +45,8 @@ module Rack::Mount
|
|
45
45
|
nil
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
X_CASCADE = 'X-Cascade'.freeze
|
49
|
+
PASS = 'pass'.freeze
|
49
50
|
PATH_INFO = 'PATH_INFO'.freeze
|
50
51
|
|
51
52
|
# Rack compatible recognition and dispatching method. Routes are
|
@@ -57,11 +58,9 @@ module Rack::Mount
|
|
57
58
|
def call(env)
|
58
59
|
raise 'route set not finalized' unless @recognition_graph
|
59
60
|
|
60
|
-
set_expectation = env[EXPECT] != '100-continue'
|
61
|
-
env[EXPECT] = '100-continue' if set_expectation
|
62
|
-
|
63
61
|
env[PATH_INFO] = Utils.normalize_path(env[PATH_INFO])
|
64
62
|
|
63
|
+
request = nil
|
65
64
|
req = @request_class.new(env)
|
66
65
|
recognize(req) do |route, params|
|
67
66
|
# TODO: We only want to unescape params from uri related methods
|
@@ -69,12 +68,10 @@ module Rack::Mount
|
|
69
68
|
|
70
69
|
env[@parameters_key] = params
|
71
70
|
result = route.app.call(env)
|
72
|
-
return result unless result[
|
71
|
+
return result unless result[1][X_CASCADE] == PASS
|
73
72
|
end
|
74
73
|
|
75
|
-
|
76
|
-
ensure
|
77
|
-
env.delete(EXPECT) if set_expectation
|
74
|
+
request || [404, {'Content-Type' => 'text/html', 'X-Cascade' => 'pass'}, ['Not Found']]
|
78
75
|
end
|
79
76
|
|
80
77
|
def rehash #:nodoc:
|
@@ -84,22 +81,15 @@ module Rack::Mount
|
|
84
81
|
super
|
85
82
|
end
|
86
83
|
|
87
|
-
def valid_conditions #:nodoc:
|
88
|
-
@valid_conditions ||= begin
|
89
|
-
conditions = @request_class.instance_methods(false)
|
90
|
-
conditions.map! { |m| m.to_sym }
|
91
|
-
conditions.freeze
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
84
|
private
|
96
85
|
def expire!
|
97
86
|
@recognition_keys = @recognition_graph = nil
|
87
|
+
@recognition_key_analyzer.expire!
|
98
88
|
super
|
99
89
|
end
|
100
90
|
|
101
91
|
def flush!
|
102
|
-
@recognition_key_analyzer =
|
92
|
+
@recognition_key_analyzer = nil
|
103
93
|
super
|
104
94
|
end
|
105
95
|
|
data/lib/rack/mount/route.rb
CHANGED
@@ -27,9 +27,7 @@ module Rack::Mount
|
|
27
27
|
# Symbol identifier for the route used with named route generations
|
28
28
|
attr_reader :name
|
29
29
|
|
30
|
-
def initialize(
|
31
|
-
@set = set
|
32
|
-
|
30
|
+
def initialize(app, conditions, defaults, name)
|
33
31
|
unless app.respond_to?(:call)
|
34
32
|
raise ArgumentError, 'app must be a valid rack application' \
|
35
33
|
' and respond to call'
|
@@ -39,19 +37,11 @@ module Rack::Mount
|
|
39
37
|
@name = name ? name.to_sym : nil
|
40
38
|
@defaults = (defaults || {}).freeze
|
41
39
|
|
42
|
-
unless conditions.is_a?(Hash)
|
43
|
-
raise ArgumentError, 'conditions must be a Hash'
|
44
|
-
end
|
45
40
|
@conditions = {}
|
46
41
|
|
47
42
|
conditions.each do |method, pattern|
|
48
43
|
next unless method && pattern
|
49
44
|
|
50
|
-
unless @set.valid_conditions.include?(method)
|
51
|
-
raise ArgumentError, 'conditions may only include ' +
|
52
|
-
@set.valid_conditions.inspect
|
53
|
-
end
|
54
|
-
|
55
45
|
pattern = Regexp.compile("\\A#{Regexp.escape(pattern)}\\Z") if pattern.is_a?(String)
|
56
46
|
pattern = Utils.normalize_extended_expression(pattern)
|
57
47
|
|
data/lib/rack/mount/route_set.rb
CHANGED
@@ -24,6 +24,12 @@ module Rack::Mount
|
|
24
24
|
# - <tt>Recognition::RouteSet.new</tt>
|
25
25
|
def initialize(options = {}, &block)
|
26
26
|
@request_class = options.delete(:request_class) || Rack::Request
|
27
|
+
@valid_conditions = begin
|
28
|
+
conditions = @request_class.instance_methods(false)
|
29
|
+
conditions.map! { |m| m.to_sym }
|
30
|
+
conditions
|
31
|
+
end
|
32
|
+
|
27
33
|
@routes = []
|
28
34
|
expire!
|
29
35
|
|
@@ -43,7 +49,8 @@ module Rack::Mount
|
|
43
49
|
# <tt>name</tt>:: Symbol identifier for the route used with named
|
44
50
|
# route generations
|
45
51
|
def add_route(app, conditions = {}, defaults = {}, name = nil)
|
46
|
-
|
52
|
+
validate_conditions!(conditions)
|
53
|
+
route = Route.new(app, conditions, defaults, name)
|
47
54
|
@routes << route
|
48
55
|
expire!
|
49
56
|
route
|
@@ -86,11 +93,55 @@ module Rack::Mount
|
|
86
93
|
super
|
87
94
|
end
|
88
95
|
|
96
|
+
def marshal_dump #:nodoc:
|
97
|
+
hash = {}
|
98
|
+
|
99
|
+
instance_variables_to_serialize.each do |ivar|
|
100
|
+
hash[ivar] = instance_variable_get(ivar)
|
101
|
+
end
|
102
|
+
|
103
|
+
if graph = hash[:@recognition_graph]
|
104
|
+
hash[:@recognition_graph] = graph.dup
|
105
|
+
end
|
106
|
+
|
107
|
+
included_modules = (class << self; included_modules; end)
|
108
|
+
included_modules.reject! { |mod| mod == Kernel }
|
109
|
+
hash[:included_modules] = included_modules
|
110
|
+
|
111
|
+
hash
|
112
|
+
end
|
113
|
+
|
114
|
+
def marshal_load(hash) #:nodoc:
|
115
|
+
hash.delete(:included_modules).reverse.each { |mod| extend(mod) }
|
116
|
+
|
117
|
+
hash.each do |ivar, value|
|
118
|
+
instance_variable_set(ivar, value)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
89
122
|
private
|
90
123
|
def expire! #:nodoc:
|
91
124
|
end
|
92
125
|
|
93
126
|
def flush! #:nodoc:
|
127
|
+
@valid_conditions = nil
|
128
|
+
end
|
129
|
+
|
130
|
+
def instance_variables_to_serialize
|
131
|
+
instance_variables.map { |ivar| ivar.to_sym }
|
132
|
+
end
|
133
|
+
|
134
|
+
def validate_conditions!(conditions)
|
135
|
+
unless conditions.is_a?(Hash)
|
136
|
+
raise ArgumentError, 'conditions must be a Hash'
|
137
|
+
end
|
138
|
+
|
139
|
+
unless conditions.all? { |method, pattern|
|
140
|
+
@valid_conditions.include?(method)
|
141
|
+
}
|
142
|
+
raise ArgumentError, 'conditions may only include ' +
|
143
|
+
@valid_conditions.inspect
|
144
|
+
end
|
94
145
|
end
|
95
146
|
|
96
147
|
# An internal helper method for constructing a nested set from
|
@@ -529,6 +529,32 @@ class Multimap
|
|
529
529
|
@hash.values_at(*keys)
|
530
530
|
end
|
531
531
|
|
532
|
+
def marshal_dump #:nodoc:
|
533
|
+
@hash
|
534
|
+
end
|
535
|
+
|
536
|
+
def marshal_load(hash) #:nodoc:
|
537
|
+
@hash = hash
|
538
|
+
end
|
539
|
+
|
540
|
+
def to_yaml(opts = {}) #:nodoc:
|
541
|
+
YAML::quick_emit(self, opts) do |out|
|
542
|
+
out.map(taguri, to_yaml_style) do |map|
|
543
|
+
@hash.each do |k, v|
|
544
|
+
map.add(k, v)
|
545
|
+
end
|
546
|
+
map.add('__default__', @hash.default)
|
547
|
+
end
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
def yaml_initialize(tag, val) #:nodoc:
|
552
|
+
default = val.delete('__default__')
|
553
|
+
@hash = val
|
554
|
+
@hash.default = default
|
555
|
+
self
|
556
|
+
end
|
557
|
+
|
532
558
|
protected
|
533
559
|
def _internal_hash #:nodoc:
|
534
560
|
@hash
|
@@ -159,4 +159,27 @@ class Multiset < Set
|
|
159
159
|
superset?(set) && subset?(set)
|
160
160
|
end
|
161
161
|
alias_method :==, :eql?
|
162
|
+
|
163
|
+
def marshal_dump #:nodoc:
|
164
|
+
@hash
|
165
|
+
end
|
166
|
+
|
167
|
+
def marshal_load(hash) #:nodoc:
|
168
|
+
@hash = hash
|
169
|
+
end
|
170
|
+
|
171
|
+
def to_yaml(opts = {}) #:nodoc:
|
172
|
+
YAML::quick_emit(self, opts) do |out|
|
173
|
+
out.map(taguri, to_yaml_style) do |map|
|
174
|
+
@hash.each do |k, v|
|
175
|
+
map.add(k, v)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def yaml_initialize(tag, val) #:nodoc:
|
182
|
+
@hash = val
|
183
|
+
self
|
184
|
+
end
|
162
185
|
end
|
@@ -54,16 +54,10 @@ class Parser < Racc::Parser
|
|
54
54
|
when (text = @ss.scan(/\\[dDsSwW]/))
|
55
55
|
action { [:CCLASS, text] }
|
56
56
|
|
57
|
-
when (text = @ss.scan(
|
58
|
-
action { [:L_ANCHOR, text] }
|
59
|
-
|
60
|
-
when (text = @ss.scan(/\\A/))
|
57
|
+
when (text = @ss.scan(/\^|\\A/))
|
61
58
|
action { [:L_ANCHOR, text] }
|
62
59
|
|
63
|
-
when (text = @ss.scan(
|
64
|
-
action { [:R_ANCHOR, text] }
|
65
|
-
|
66
|
-
when (text = @ss.scan(/\\Z/))
|
60
|
+
when (text = @ss.scan(/\$|\\Z/))
|
67
61
|
action { [:R_ANCHOR, text] }
|
68
62
|
|
69
63
|
when (text = @ss.scan(/<(\w+)>/))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-mount
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Peek
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-24 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|