rack-mount 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack/mount/analysis/frequency.rb +3 -3
- data/lib/rack/mount/generation/route.rb +10 -5
- data/lib/rack/mount/generation/route_set.rb +25 -6
- data/lib/rack/mount/strexp/parser.rb +0 -0
- data/lib/rack/mount/strexp/parser.y +33 -0
- data/lib/rack/mount/strexp/tokenizer.rex +12 -0
- data/lib/rack/mount/vendor/reginald/reginald/expression.rb +24 -0
- data/lib/rack/mount/vendor/reginald/reginald/parser.rb +11 -10
- data/lib/rack/mount/version.rb +3 -0
- metadata +21 -22
@@ -36,10 +36,10 @@ module Rack::Mount
|
|
36
36
|
def process_key(requirements, method, requirement)
|
37
37
|
if requirement.is_a?(Regexp)
|
38
38
|
expression = Utils.parse_regexp(requirement)
|
39
|
-
expression = expression.reject { |e| e.is_a?(Reginald::Anchor) }
|
40
39
|
|
41
|
-
if expression.is_a?(Reginald::Expression) && expression.
|
42
|
-
|
40
|
+
if expression.is_a?(Reginald::Expression) && expression.anchored_to_line?
|
41
|
+
expression = expression.reject { |e| e.is_a?(Reginald::Anchor) }
|
42
|
+
return requirements[method] = expression.to_s if expression.literal?
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -26,12 +26,17 @@ module Rack::Mount
|
|
26
26
|
@has_significant_params
|
27
27
|
end
|
28
28
|
|
29
|
-
def generate(
|
30
|
-
if
|
31
|
-
result =
|
32
|
-
|
29
|
+
def generate(method, params = {}, recall = {}, options = {})
|
30
|
+
if method.nil?
|
31
|
+
result = @conditions.inject({}) { |h, (method, condition)|
|
32
|
+
if condition.respond_to?(:generate)
|
33
|
+
h[method] = condition.generate(params, recall, options)
|
34
|
+
end
|
35
|
+
h
|
36
|
+
}
|
37
|
+
return nil if result.values.compact.empty?
|
33
38
|
else
|
34
|
-
result = generate_method(
|
39
|
+
result = generate_method(method, params, recall, options)
|
35
40
|
end
|
36
41
|
|
37
42
|
if result
|
@@ -51,7 +51,7 @@ module Rack::Mount
|
|
51
51
|
only_path = params.delete(:only_path)
|
52
52
|
recall = env[@parameters_key] || {}
|
53
53
|
|
54
|
-
unless result = generate(
|
54
|
+
unless result = generate(:all, named_route, params, recall,
|
55
55
|
:parameterize => lambda { |name, param| Utils.escape_uri(param) })
|
56
56
|
return
|
57
57
|
end
|
@@ -67,16 +67,15 @@ module Rack::Mount
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
req =
|
71
|
-
|
72
|
-
|
73
|
-
uri << "?#{Utils.build_nested_query(params)}" if params.any?
|
74
|
-
uri
|
70
|
+
req = stubbed_request_class.new(env)
|
71
|
+
req._stubbed_values = parts.merge(:query_string => Utils.build_nested_query(params))
|
72
|
+
only_path ? req.fullpath : req.url
|
75
73
|
end
|
76
74
|
|
77
75
|
def generate(method, *args) #:nodoc:
|
78
76
|
raise 'route set not finalized' unless @generation_graph
|
79
77
|
|
78
|
+
method = nil if method == :all
|
80
79
|
named_route, params, recall, options = extract_params!(*args)
|
81
80
|
merged = recall.merge(params)
|
82
81
|
route = nil
|
@@ -176,6 +175,26 @@ module Rack::Mount
|
|
176
175
|
|
177
176
|
[named_route, params.dup, recall.dup, options.dup]
|
178
177
|
end
|
178
|
+
|
179
|
+
def instance_variables_to_serialize
|
180
|
+
super - [:@stubbed_request_class]
|
181
|
+
end
|
182
|
+
|
183
|
+
def stubbed_request_class
|
184
|
+
@stubbed_request_class ||= begin
|
185
|
+
klass = Class.new(@request_class)
|
186
|
+
klass.public_instance_methods.each do |method|
|
187
|
+
next if method =~ /^__|object_id/
|
188
|
+
klass.class_eval <<-RUBY
|
189
|
+
def #{method}(*args, &block)
|
190
|
+
@_stubbed_values[:#{method}] || super
|
191
|
+
end
|
192
|
+
RUBY
|
193
|
+
end
|
194
|
+
klass.class_eval { attr_accessor :_stubbed_values }
|
195
|
+
klass
|
196
|
+
end
|
197
|
+
end
|
179
198
|
end
|
180
199
|
end
|
181
200
|
end
|
Binary file
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Rack::Mount::StrexpParser
|
2
|
+
rule
|
3
|
+
target: expr { result = anchor ? "\\A#{val.join}\\Z" : "\\A#{val.join}" }
|
4
|
+
|
5
|
+
expr: expr token { result = val.join }
|
6
|
+
| token
|
7
|
+
|
8
|
+
token: PARAM {
|
9
|
+
name = val[0].to_sym
|
10
|
+
requirement = requirements[name]
|
11
|
+
result = REGEXP_NAMED_CAPTURE % [name, requirement]
|
12
|
+
}
|
13
|
+
| GLOB {
|
14
|
+
name = val[0].to_sym
|
15
|
+
result = REGEXP_NAMED_CAPTURE % [name, '.+']
|
16
|
+
}
|
17
|
+
| LPAREN expr RPAREN { result = "(?:#{val[1]})?" }
|
18
|
+
| CHAR { result = Regexp.escape(val[0]) }
|
19
|
+
end
|
20
|
+
|
21
|
+
---- header ----
|
22
|
+
require 'rack/mount/utils'
|
23
|
+
require 'rack/mount/strexp/tokenizer'
|
24
|
+
|
25
|
+
---- inner
|
26
|
+
|
27
|
+
if Reginald.regexp_supports_named_captures?
|
28
|
+
REGEXP_NAMED_CAPTURE = '(?<%s>%s)'.freeze
|
29
|
+
else
|
30
|
+
REGEXP_NAMED_CAPTURE = '(?:<%s>%s)'.freeze
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_accessor :anchor, :requirements
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Rack::Mount::StrexpParser
|
2
|
+
macro
|
3
|
+
RESERVED \(|\)|:|\*
|
4
|
+
ALPHA_U [a-zA-Z_]
|
5
|
+
rule
|
6
|
+
\\({RESERVED}) { [:CHAR, @ss[1]] }
|
7
|
+
\:({ALPHA_U}\w*) { [:PARAM, @ss[1]] }
|
8
|
+
\*({ALPHA_U}\w*) { [:GLOB, @ss[1]] }
|
9
|
+
\( { [:LPAREN, text] }
|
10
|
+
\) { [:RPAREN, text] }
|
11
|
+
. { [:CHAR, text] }
|
12
|
+
end
|
@@ -41,6 +41,30 @@ module Reginald
|
|
41
41
|
!ignorecase && all? { |e| e.literal? }
|
42
42
|
end
|
43
43
|
|
44
|
+
def anchored?
|
45
|
+
anchored_to_start? && anchored_to_end?
|
46
|
+
end
|
47
|
+
|
48
|
+
def anchored_to_start?
|
49
|
+
first.is_a?(Anchor) && first == '\A'
|
50
|
+
end
|
51
|
+
|
52
|
+
def anchored_to_end?
|
53
|
+
last.is_a?(Anchor) && last == '\Z'
|
54
|
+
end
|
55
|
+
|
56
|
+
def anchored_to_line?
|
57
|
+
anchored_to_start_of_line? && anchored_to_end_of_line?
|
58
|
+
end
|
59
|
+
|
60
|
+
def anchored_to_start_of_line?
|
61
|
+
anchored_to_start? || (first.is_a?(Anchor) && first == '^')
|
62
|
+
end
|
63
|
+
|
64
|
+
def anchored_to_end_of_line?
|
65
|
+
anchored_to_end? || (last.is_a?(Anchor) && last == '$')
|
66
|
+
end
|
67
|
+
|
44
68
|
def options
|
45
69
|
flag = 0
|
46
70
|
flag |= Regexp::MULTILINE if multiline
|
@@ -298,7 +298,7 @@ end
|
|
298
298
|
def _reduce_3(val, _values, result)
|
299
299
|
val[1].quantifier = val[2]
|
300
300
|
result = Expression.reduce(val[0], val[1])
|
301
|
-
|
301
|
+
|
302
302
|
result
|
303
303
|
end
|
304
304
|
|
@@ -310,7 +310,7 @@ end
|
|
310
310
|
def _reduce_5(val, _values, result)
|
311
311
|
val[0].quantifier = val[1]
|
312
312
|
result = val[0]
|
313
|
-
|
313
|
+
|
314
314
|
result
|
315
315
|
end
|
316
316
|
|
@@ -356,7 +356,7 @@ end
|
|
356
356
|
def _reduce_15(val, _values, result)
|
357
357
|
result = Group.new(val[1])
|
358
358
|
result.index = @capture_index_stack.pop
|
359
|
-
|
359
|
+
|
360
360
|
result
|
361
361
|
end
|
362
362
|
|
@@ -368,14 +368,14 @@ def _reduce_16(val, _values, result)
|
|
368
368
|
result.expression.ignorecase = options[:ignorecase];
|
369
369
|
result.expression.extended = options[:extended];
|
370
370
|
@options_stack.pop
|
371
|
-
|
371
|
+
|
372
372
|
result
|
373
373
|
end
|
374
374
|
|
375
375
|
def _reduce_17(val, _values, result)
|
376
376
|
result = Group.new(val[3]);
|
377
377
|
result.capture = false;
|
378
|
-
|
378
|
+
|
379
379
|
result
|
380
380
|
end
|
381
381
|
|
@@ -383,7 +383,7 @@ def _reduce_18(val, _values, result)
|
|
383
383
|
result = Group.new(val[3]);
|
384
384
|
result.name = val[2];
|
385
385
|
result.index = @capture_index_stack.pop
|
386
|
-
|
386
|
+
|
387
387
|
result
|
388
388
|
end
|
389
389
|
|
@@ -493,25 +493,25 @@ end
|
|
493
493
|
|
494
494
|
def _reduce_44(val, _values, result)
|
495
495
|
@options_stack << result = { val[1] => false, val[2] => false, val[3] => false }
|
496
|
-
|
496
|
+
|
497
497
|
result
|
498
498
|
end
|
499
499
|
|
500
500
|
def _reduce_45(val, _values, result)
|
501
501
|
@options_stack << result = { val[0] => true, val[2] => false, val[3] => false }
|
502
|
-
|
502
|
+
|
503
503
|
result
|
504
504
|
end
|
505
505
|
|
506
506
|
def _reduce_46(val, _values, result)
|
507
507
|
@options_stack << result = { val[0] => true, val[1] => true, val[3] => false }
|
508
|
-
|
508
|
+
|
509
509
|
result
|
510
510
|
end
|
511
511
|
|
512
512
|
def _reduce_47(val, _values, result)
|
513
513
|
@options_stack << result = { val[0] => true, val[1] => true, val[2] => true }
|
514
|
-
|
514
|
+
|
515
515
|
result
|
516
516
|
end
|
517
517
|
|
@@ -538,3 +538,4 @@ end
|
|
538
538
|
end # module Reginald
|
539
539
|
|
540
540
|
require 'reginald/tokenizer'
|
541
|
+
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-mount
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 6
|
8
|
+
- 1
|
9
|
+
version: 0.6.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Joshua Peek
|
@@ -9,19 +14,10 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-06 00:00:00 -06:00
|
13
18
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
name: rack
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.0.0
|
24
|
-
version:
|
19
|
+
dependencies: []
|
20
|
+
|
25
21
|
description: Stackable dynamic tree based Rack router
|
26
22
|
email: josh@joshpeek.com
|
27
23
|
executables: []
|
@@ -29,9 +25,10 @@ executables: []
|
|
29
25
|
extensions: []
|
30
26
|
|
31
27
|
extra_rdoc_files:
|
32
|
-
- README.rdoc
|
33
28
|
- LICENSE
|
29
|
+
- README.rdoc
|
34
30
|
files:
|
31
|
+
- lib/rack/mount.rb
|
35
32
|
- lib/rack/mount/analysis/frequency.rb
|
36
33
|
- lib/rack/mount/analysis/histogram.rb
|
37
34
|
- lib/rack/mount/analysis/splitting.rb
|
@@ -48,13 +45,16 @@ files:
|
|
48
45
|
- lib/rack/mount/regexp_with_named_groups.rb
|
49
46
|
- lib/rack/mount/route.rb
|
50
47
|
- lib/rack/mount/route_set.rb
|
48
|
+
- lib/rack/mount/strexp.rb
|
51
49
|
- lib/rack/mount/strexp/parser.rb
|
50
|
+
- lib/rack/mount/strexp/parser.y
|
52
51
|
- lib/rack/mount/strexp/tokenizer.rb
|
53
|
-
- lib/rack/mount/strexp.
|
52
|
+
- lib/rack/mount/strexp/tokenizer.rex
|
54
53
|
- lib/rack/mount/utils.rb
|
55
54
|
- lib/rack/mount/vendor/multimap/multimap.rb
|
56
55
|
- lib/rack/mount/vendor/multimap/multiset.rb
|
57
56
|
- lib/rack/mount/vendor/multimap/nested_multimap.rb
|
57
|
+
- lib/rack/mount/vendor/reginald/reginald.rb
|
58
58
|
- lib/rack/mount/vendor/reginald/reginald/alternation.rb
|
59
59
|
- lib/rack/mount/vendor/reginald/reginald/anchor.rb
|
60
60
|
- lib/rack/mount/vendor/reginald/reginald/atom.rb
|
@@ -65,10 +65,7 @@ files:
|
|
65
65
|
- lib/rack/mount/vendor/reginald/reginald/group.rb
|
66
66
|
- lib/rack/mount/vendor/reginald/reginald/parser.rb
|
67
67
|
- lib/rack/mount/vendor/reginald/reginald/tokenizer.rb
|
68
|
-
- lib/rack/mount/
|
69
|
-
- lib/rack/mount.rb
|
70
|
-
- README.rdoc
|
71
|
-
- LICENSE
|
68
|
+
- lib/rack/mount/version.rb
|
72
69
|
has_rdoc: true
|
73
70
|
homepage: http://github.com/josh/rack-mount
|
74
71
|
licenses: []
|
@@ -82,18 +79,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
79
|
requirements:
|
83
80
|
- - ">="
|
84
81
|
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
85
84
|
version: "0"
|
86
|
-
version:
|
87
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
86
|
requirements:
|
89
87
|
- - ">="
|
90
88
|
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
91
91
|
version: "0"
|
92
|
-
version:
|
93
92
|
requirements: []
|
94
93
|
|
95
94
|
rubyforge_project:
|
96
|
-
rubygems_version: 1.3.
|
95
|
+
rubygems_version: 1.3.6
|
97
96
|
signing_key:
|
98
97
|
specification_version: 3
|
99
98
|
summary: Stackable dynamic tree based Rack router
|