rack-mount 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack/mount/generation/route_set.rb +5 -0
- data/lib/rack/mount/multimap.rb +0 -41
- data/lib/rack/mount/recognition/route_set.rb +5 -0
- data/lib/rack/mount/route_set.rb +4 -0
- data/lib/rack/mount/vendor/multimap/multimap.rb +11 -0
- data/lib/rack/mount/vendor/multimap/multiset.rb +10 -1
- data/lib/rack/mount/vendor/multimap/nested_multimap.rb +16 -14
- data/lib/rack/mount/vendor/reginald/reginald.rb +10 -1
- data/lib/rack/mount/vendor/reginald/reginald/alternation.rb +5 -2
- data/lib/rack/mount/vendor/reginald/reginald/atom.rb +5 -4
- data/lib/rack/mount/vendor/reginald/reginald/character.rb +5 -2
- data/lib/rack/mount/vendor/reginald/reginald/character_class.rb +5 -2
- data/lib/rack/mount/vendor/reginald/reginald/collection.rb +3 -3
- data/lib/rack/mount/vendor/reginald/reginald/expression.rb +6 -3
- data/lib/rack/mount/vendor/reginald/reginald/group.rb +7 -4
- data/lib/rack/mount/vendor/reginald/reginald/parser.rb +1 -1
- metadata +2 -2
@@ -101,6 +101,11 @@ module Rack::Mount
|
|
101
101
|
super
|
102
102
|
end
|
103
103
|
|
104
|
+
def flush!
|
105
|
+
@generation_key_analyzer = nil
|
106
|
+
super
|
107
|
+
end
|
108
|
+
|
104
109
|
def build_generation_graph
|
105
110
|
build_nested_route_set(@generation_keys) { |k, i|
|
106
111
|
throw :skip unless @routes[i].significant_params?
|
data/lib/rack/mount/multimap.rb
CHANGED
@@ -7,22 +7,6 @@ end
|
|
7
7
|
|
8
8
|
module Rack::Mount
|
9
9
|
class Multimap < NestedMultimap #:nodoc:
|
10
|
-
def self.[](*args)
|
11
|
-
map = super
|
12
|
-
map.instance_variable_set('@fuzz', {})
|
13
|
-
map
|
14
|
-
end
|
15
|
-
|
16
|
-
def initialize(default = [])
|
17
|
-
@fuzz = {}
|
18
|
-
super
|
19
|
-
end
|
20
|
-
|
21
|
-
def initialize_copy(original)
|
22
|
-
@fuzz = original.instance_variable_get('@fuzz').dup
|
23
|
-
super
|
24
|
-
end
|
25
|
-
|
26
10
|
def store(*args)
|
27
11
|
keys = args.dup
|
28
12
|
value = keys.pop
|
@@ -35,7 +19,6 @@ module Rack::Mount
|
|
35
19
|
end
|
36
20
|
|
37
21
|
if key.is_a?(Regexp)
|
38
|
-
@fuzz[value] = key
|
39
22
|
if keys.empty?
|
40
23
|
@hash.each_pair { |k, l| l << value if k =~ key }
|
41
24
|
self.default << value
|
@@ -56,12 +39,6 @@ module Rack::Mount
|
|
56
39
|
end
|
57
40
|
alias_method :[]=, :store
|
58
41
|
|
59
|
-
def freeze
|
60
|
-
@fuzz.clear
|
61
|
-
@fuzz = nil
|
62
|
-
super
|
63
|
-
end
|
64
|
-
|
65
42
|
undef :index, :invert
|
66
43
|
|
67
44
|
def height
|
@@ -72,23 +49,5 @@ module Rack::Mount
|
|
72
49
|
lengths = containers_with_default.map { |e| e.length }
|
73
50
|
lengths.inject(0) { |sum, len| sum += len }.to_f / lengths.size
|
74
51
|
end
|
75
|
-
|
76
|
-
protected
|
77
|
-
def update_container(key) #:nodoc:
|
78
|
-
super do |container|
|
79
|
-
if container.is_a?(self.class)
|
80
|
-
container.each_container_with_default do |c|
|
81
|
-
c.delete_if do |value|
|
82
|
-
(requirement = @fuzz[value]) && key !~ requirement
|
83
|
-
end
|
84
|
-
end
|
85
|
-
else
|
86
|
-
container.delete_if do |value|
|
87
|
-
(requirement = @fuzz[value]) && key !~ requirement
|
88
|
-
end
|
89
|
-
end
|
90
|
-
yield container
|
91
|
-
end
|
92
|
-
end
|
93
52
|
end
|
94
53
|
end
|
@@ -98,6 +98,11 @@ module Rack::Mount
|
|
98
98
|
super
|
99
99
|
end
|
100
100
|
|
101
|
+
def flush!
|
102
|
+
@recognition_key_analyzer = @valid_conditions = nil
|
103
|
+
super
|
104
|
+
end
|
105
|
+
|
101
106
|
def build_recognition_graph
|
102
107
|
build_nested_route_set(@recognition_keys) { |k, i|
|
103
108
|
@recognition_key_analyzer.possible_keys[i][k]
|
data/lib/rack/mount/route_set.rb
CHANGED
@@ -78,6 +78,7 @@ module Rack::Mount
|
|
78
78
|
def freeze
|
79
79
|
unless frozen?
|
80
80
|
rehash
|
81
|
+
flush!
|
81
82
|
@routes.each { |route| route.freeze }
|
82
83
|
@routes.freeze
|
83
84
|
end
|
@@ -89,6 +90,9 @@ module Rack::Mount
|
|
89
90
|
def expire! #:nodoc:
|
90
91
|
end
|
91
92
|
|
93
|
+
def flush! #:nodoc:
|
94
|
+
end
|
95
|
+
|
92
96
|
# An internal helper method for constructing a nested set from
|
93
97
|
# the linear route set.
|
94
98
|
#
|
@@ -4,6 +4,17 @@ require 'multiset'
|
|
4
4
|
# Multimap is a generalization of a map or associative array
|
5
5
|
# abstract data type in which more than one value may be associated
|
6
6
|
# with and returned for a given key.
|
7
|
+
#
|
8
|
+
# == Example
|
9
|
+
#
|
10
|
+
# require 'multimap'
|
11
|
+
# map = Multimap.new
|
12
|
+
# map["a"] = 100
|
13
|
+
# map["b"] = 200
|
14
|
+
# map["a"] = 300
|
15
|
+
# map["a"] # -> [100, 300]
|
16
|
+
# map["b"] # -> [200]
|
17
|
+
# map.keys # -> #<Multiset: {a, a, b}>
|
7
18
|
class Multimap
|
8
19
|
extend Forwardable
|
9
20
|
|
@@ -1,7 +1,16 @@
|
|
1
1
|
require 'set'
|
2
2
|
|
3
3
|
# Multiset implements a collection of unordered values and
|
4
|
-
# allows
|
4
|
+
# allows duplicates.
|
5
|
+
#
|
6
|
+
# == Example
|
7
|
+
#
|
8
|
+
# require 'multiset'
|
9
|
+
# s1 = Multiset.new [1, 2] # -> #<Multiset: {1, 2}>
|
10
|
+
# s1.add(2) # -> #<Multiset: {1, 2, 2}>
|
11
|
+
# s1.merge([2, 6]) # -> #<Multiset: {1, 2, 2, 2, 3}>
|
12
|
+
# s1.multiplicity(2) # -> 3
|
13
|
+
# s1.multiplicity(3) # -> 1
|
5
14
|
class Multiset < Set
|
6
15
|
def initialize(*args, &block) #:nodoc:
|
7
16
|
@hash = Hash.new(0)
|
@@ -45,7 +45,7 @@ class NestedMultimap < Multimap
|
|
45
45
|
# map["a"] #=> [100, 300]
|
46
46
|
# map["c"] #=> [300]
|
47
47
|
def <<(value)
|
48
|
-
@hash.
|
48
|
+
@hash.each_value { |container| container << value }
|
49
49
|
self.default << value
|
50
50
|
self
|
51
51
|
end
|
@@ -111,20 +111,11 @@ class NestedMultimap < Multimap
|
|
111
111
|
# [100, 101, 102]
|
112
112
|
# [100, 102]
|
113
113
|
# []
|
114
|
-
def each_container_with_default
|
115
|
-
|
116
|
-
|
117
|
-
container.each_container_with_default do |value|
|
118
|
-
yield value
|
119
|
-
end
|
120
|
-
else
|
121
|
-
yield container
|
122
|
-
end
|
114
|
+
def each_container_with_default(&block)
|
115
|
+
@hash.each_value do |container|
|
116
|
+
iterate_over_container(container, &block)
|
123
117
|
end
|
124
|
-
|
125
|
-
@hash.each_pair { |_, container| each_container.call(container) }
|
126
|
-
each_container.call(default)
|
127
|
-
|
118
|
+
iterate_over_container(default, &block)
|
128
119
|
self
|
129
120
|
end
|
130
121
|
|
@@ -148,6 +139,17 @@ class NestedMultimap < Multimap
|
|
148
139
|
def inspect #:nodoc:
|
149
140
|
super.gsub(/\}$/, ", default => #{default.inspect}}")
|
150
141
|
end
|
142
|
+
|
143
|
+
private
|
144
|
+
def iterate_over_container(container)
|
145
|
+
if container.respond_to?(:each_container_with_default)
|
146
|
+
container.each_container_with_default do |value|
|
147
|
+
yield value
|
148
|
+
end
|
149
|
+
else
|
150
|
+
yield container
|
151
|
+
end
|
152
|
+
end
|
151
153
|
end
|
152
154
|
|
153
155
|
begin
|
@@ -13,19 +13,28 @@ module Reginald
|
|
13
13
|
begin
|
14
14
|
eval('foo = /(?<foo>.*)/').named_captures
|
15
15
|
|
16
|
+
# Returns true if the interpreter is using the Oniguruma Regexp lib
|
17
|
+
# and supports named captures.
|
18
|
+
#
|
19
|
+
# /(?<foo>bar)/
|
16
20
|
def regexp_supports_named_captures?
|
17
21
|
true
|
18
22
|
end
|
19
23
|
rescue SyntaxError, NoMethodError
|
20
|
-
def regexp_supports_named_captures?
|
24
|
+
def regexp_supports_named_captures? #:nodoc:
|
21
25
|
false
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
29
|
+
# Parses Regexp and returns a Expression data structure.
|
25
30
|
def parse(regexp)
|
26
31
|
Parser.parse_regexp(regexp)
|
27
32
|
end
|
28
33
|
|
34
|
+
# Recompiles Regexp by parsing it and turning it back into a Regexp.
|
35
|
+
#
|
36
|
+
# (In the future Reginald will perform some Regexp optimizations
|
37
|
+
# such as removing unnecessary captures and options)
|
29
38
|
def compile(source)
|
30
39
|
regexp = Regexp.compile(source)
|
31
40
|
expression = parse(regexp)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Reginald
|
2
2
|
class Alternation < Collection
|
3
|
-
def self.reduce(alternation_or_expression, expression)
|
3
|
+
def self.reduce(alternation_or_expression, expression) #:nodoc:
|
4
4
|
if alternation_or_expression.first.is_a?(Alternation)
|
5
5
|
alternation_or_expression = alternation_or_expression.first
|
6
6
|
alternation_or_expression << expression
|
@@ -18,6 +18,9 @@ module Reginald
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
# Returns true if expression could be treated as a literal string.
|
22
|
+
#
|
23
|
+
# Alternation groups are never literal.
|
21
24
|
def literal?
|
22
25
|
false
|
23
26
|
end
|
@@ -30,7 +33,7 @@ module Reginald
|
|
30
33
|
map { |e| e.to_s(parent) }.join('|')
|
31
34
|
end
|
32
35
|
|
33
|
-
def inspect
|
36
|
+
def inspect #:nodoc:
|
34
37
|
to_s.inspect
|
35
38
|
end
|
36
39
|
end
|
@@ -7,6 +7,7 @@ module Reginald
|
|
7
7
|
super
|
8
8
|
end
|
9
9
|
|
10
|
+
# Returns true if expression could be treated as a literal string.
|
10
11
|
def literal?
|
11
12
|
false
|
12
13
|
end
|
@@ -19,11 +20,11 @@ module Reginald
|
|
19
20
|
"#{value}"
|
20
21
|
end
|
21
22
|
|
22
|
-
def inspect
|
23
|
+
def inspect #:nodoc:
|
23
24
|
"#<#{self.class.to_s.sub('Reginald::', '')} #{to_s.inspect}>"
|
24
25
|
end
|
25
26
|
|
26
|
-
def ==(other)
|
27
|
+
def ==(other) #:nodoc:
|
27
28
|
case other
|
28
29
|
when String
|
29
30
|
other == to_s
|
@@ -32,13 +33,13 @@ module Reginald
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
def eql?(other)
|
36
|
+
def eql?(other) #:nodoc:
|
36
37
|
other.instance_of?(self.class) &&
|
37
38
|
self.value.eql?(other.value) &&
|
38
39
|
(!!self.ignorecase).eql?(!!other.ignorecase)
|
39
40
|
end
|
40
41
|
|
41
|
-
def freeze
|
42
|
+
def freeze #:nodoc:
|
42
43
|
value.freeze
|
43
44
|
super
|
44
45
|
end
|
@@ -2,6 +2,9 @@ module Reginald
|
|
2
2
|
class Character < Atom
|
3
3
|
attr_accessor :quantifier
|
4
4
|
|
5
|
+
# Returns true if expression could be treated as a literal string.
|
6
|
+
#
|
7
|
+
# A Character is literal is there is no quantifier attached to it.
|
5
8
|
def literal?
|
6
9
|
quantifier.nil? && !ignorecase
|
7
10
|
end
|
@@ -30,11 +33,11 @@ module Reginald
|
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
33
|
-
def eql?(other)
|
36
|
+
def eql?(other) #:nodoc:
|
34
37
|
super && quantifier.eql?(other.quantifier)
|
35
38
|
end
|
36
39
|
|
37
|
-
def freeze
|
40
|
+
def freeze #:nodoc:
|
38
41
|
quantifier.freeze
|
39
42
|
super
|
40
43
|
end
|
@@ -27,6 +27,9 @@ module Reginald
|
|
27
27
|
negate ? true : false
|
28
28
|
end
|
29
29
|
|
30
|
+
# Returns true if expression could be treated as a literal string.
|
31
|
+
#
|
32
|
+
# A CharacterClass is never literal.
|
30
33
|
def literal?
|
31
34
|
false
|
32
35
|
end
|
@@ -52,11 +55,11 @@ module Reginald
|
|
52
55
|
Regexp.compile("\\A#{re}\\Z").match(char)
|
53
56
|
end
|
54
57
|
|
55
|
-
def eql?(other)
|
58
|
+
def eql?(other) #:nodoc:
|
56
59
|
super && negate == other.negate
|
57
60
|
end
|
58
61
|
|
59
|
-
def freeze
|
62
|
+
def freeze #:nodoc:
|
60
63
|
negate.freeze
|
61
64
|
super
|
62
65
|
end
|
@@ -17,7 +17,7 @@ module Reginald
|
|
17
17
|
any? { |e| e.include?(char) }
|
18
18
|
end
|
19
19
|
|
20
|
-
def ==(other)
|
20
|
+
def ==(other) #:nodoc:
|
21
21
|
case other
|
22
22
|
when String
|
23
23
|
other == to_s
|
@@ -28,11 +28,11 @@ module Reginald
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def eql?(other)
|
31
|
+
def eql?(other) #:nodoc:
|
32
32
|
other.instance_of?(self.class) && super
|
33
33
|
end
|
34
34
|
|
35
|
-
def freeze
|
35
|
+
def freeze #:nodoc:
|
36
36
|
each { |e| e.freeze }
|
37
37
|
super
|
38
38
|
end
|
@@ -3,7 +3,7 @@ module Reginald
|
|
3
3
|
attr_reader :ignorecase
|
4
4
|
attr_accessor :multiline, :extended
|
5
5
|
|
6
|
-
def self.reduce(expression_or_atom, atom = nil)
|
6
|
+
def self.reduce(expression_or_atom, atom = nil) #:nodoc:
|
7
7
|
if expression_or_atom.is_a?(Expression)
|
8
8
|
expression_or_atom << atom if atom
|
9
9
|
new(*expression_or_atom)
|
@@ -34,6 +34,9 @@ module Reginald
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
# Returns true if expression could be treated as a literal string.
|
38
|
+
#
|
39
|
+
# A Expression is literal if all its elements are literal.
|
37
40
|
def literal?
|
38
41
|
!ignorecase && all? { |e| e.literal? }
|
39
42
|
end
|
@@ -69,7 +72,7 @@ module Reginald
|
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
72
|
-
def inspect
|
75
|
+
def inspect #:nodoc:
|
73
76
|
"#<Expression #{to_s.inspect}>"
|
74
77
|
end
|
75
78
|
|
@@ -77,7 +80,7 @@ module Reginald
|
|
77
80
|
ignorecase
|
78
81
|
end
|
79
82
|
|
80
|
-
def eql?(other)
|
83
|
+
def eql?(other) #:nodoc:
|
81
84
|
super &&
|
82
85
|
!!self.multiline == !!other.multiline &&
|
83
86
|
!!self.ignorecase == !!other.ignorecase &&
|
@@ -11,6 +11,9 @@ module Reginald
|
|
11
11
|
expression.ignorecase = ignorecase
|
12
12
|
end
|
13
13
|
|
14
|
+
# Returns true if expression could be treated as a literal string.
|
15
|
+
#
|
16
|
+
# A Group is literal if its expression is literal and it has no quantifier.
|
14
17
|
def literal?
|
15
18
|
quantifier.nil? && expression.literal?
|
16
19
|
end
|
@@ -29,7 +32,7 @@ module Reginald
|
|
29
32
|
Regexp.compile("\\A#{to_s}\\Z")
|
30
33
|
end
|
31
34
|
|
32
|
-
def inspect
|
35
|
+
def inspect #:nodoc:
|
33
36
|
to_s.inspect
|
34
37
|
end
|
35
38
|
|
@@ -45,7 +48,7 @@ module Reginald
|
|
45
48
|
capture
|
46
49
|
end
|
47
50
|
|
48
|
-
def ==(other)
|
51
|
+
def ==(other) #:nodoc:
|
49
52
|
case other
|
50
53
|
when String
|
51
54
|
other == to_s
|
@@ -54,7 +57,7 @@ module Reginald
|
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
57
|
-
def eql?(other)
|
60
|
+
def eql?(other) #:nodoc:
|
58
61
|
other.is_a?(self.class) &&
|
59
62
|
self.expression == other.expression &&
|
60
63
|
self.quantifier == other.quantifier &&
|
@@ -63,7 +66,7 @@ module Reginald
|
|
63
66
|
self.name == other.name
|
64
67
|
end
|
65
68
|
|
66
|
-
def freeze
|
69
|
+
def freeze #:nodoc:
|
67
70
|
expression.freeze
|
68
71
|
super
|
69
72
|
end
|
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.3.
|
4
|
+
version: 0.3.3
|
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-22 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|