rack-mount 0.2.2 → 0.2.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.
@@ -62,20 +62,20 @@ module Rack::Mount
|
|
62
62
|
if part.is_a?(Reginald::Group)
|
63
63
|
if index > 0
|
64
64
|
previous = parts[index-1]
|
65
|
-
if previous.literal?
|
65
|
+
if previous.is_a?(Reginald::Character) && previous.literal?
|
66
66
|
boundaries << previous.to_s
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
if inside = part[0][0]
|
71
|
-
if inside.literal?
|
71
|
+
if inside.is_a?(Reginald::Character) && inside.literal?
|
72
72
|
boundaries << inside.to_s
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
if index < parts.length
|
77
77
|
following = parts[index+1]
|
78
|
-
if following.literal?
|
78
|
+
if following.is_a?(Reginald::Character) && following.literal?
|
79
79
|
boundaries << following.to_s
|
80
80
|
end
|
81
81
|
end
|
data/lib/rack/mount/multimap.rb
CHANGED
@@ -37,10 +37,10 @@ module Rack::Mount
|
|
37
37
|
if key.is_a?(Regexp)
|
38
38
|
@fuzz[value] = key
|
39
39
|
if keys.empty?
|
40
|
-
|
40
|
+
@hash.each_pair { |k, l| l << value if k =~ key }
|
41
41
|
self.default << value
|
42
42
|
else
|
43
|
-
|
43
|
+
@hash.each_pair { |k, _|
|
44
44
|
if k =~ key
|
45
45
|
args[0] = k
|
46
46
|
super(*args)
|
@@ -1,22 +1,13 @@
|
|
1
|
+
require 'forwardable'
|
1
2
|
require 'multiset'
|
2
3
|
|
3
4
|
# Multimap is a generalization of a map or associative array
|
4
5
|
# abstract data type in which more than one value may be associated
|
5
6
|
# with and returned for a given key.
|
6
|
-
class Multimap
|
7
|
-
|
8
|
-
# Ignore protected aliases back to the original Hash methods
|
9
|
-
#++
|
10
|
-
module_eval %{
|
11
|
-
alias_method :hash_aref, :[]
|
12
|
-
protected :hash_aref
|
7
|
+
class Multimap
|
8
|
+
extend Forwardable
|
13
9
|
|
14
|
-
|
15
|
-
protected :hash_aset
|
16
|
-
|
17
|
-
alias_method :hash_each_pair, :each_pair
|
18
|
-
protected :hash_each_pair
|
19
|
-
}
|
10
|
+
include Enumerable
|
20
11
|
|
21
12
|
# call-seq:
|
22
13
|
# Multimap[ [key =>|, value]* ] => multimap
|
@@ -53,7 +44,8 @@ class Multimap < Hash
|
|
53
44
|
}
|
54
45
|
end
|
55
46
|
|
56
|
-
map =
|
47
|
+
map = new
|
48
|
+
map.instance_variable_set(:@hash, Hash[*args])
|
57
49
|
map.default = default
|
58
50
|
map
|
59
51
|
end
|
@@ -70,20 +62,24 @@ class Multimap < Hash
|
|
70
62
|
# h["a"] #=> [100].to_set
|
71
63
|
# h["c"] #=> [].to_set
|
72
64
|
def initialize(default = [])
|
73
|
-
|
65
|
+
@hash = Hash.new(default)
|
74
66
|
end
|
75
67
|
|
76
68
|
def initialize_copy(original) #:nodoc:
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
69
|
+
@hash = Hash.new(original.default.dup)
|
70
|
+
original._internal_hash.each_pair do |key, container|
|
71
|
+
@hash[key] = container.dup
|
72
|
+
end
|
81
73
|
end
|
82
74
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
75
|
+
def_delegators :@hash, :clear, :default, :default=, :empty?,
|
76
|
+
:fetch, :has_key?, :key?
|
77
|
+
|
78
|
+
# Retrieves the <i>value</i> object corresponding to the
|
79
|
+
# <i>*keys</i> object.
|
80
|
+
def [](key)
|
81
|
+
@hash[key]
|
82
|
+
end
|
87
83
|
|
88
84
|
# call-seq:
|
89
85
|
# map[key] = value => value
|
@@ -118,9 +114,9 @@ class Multimap < Hash
|
|
118
114
|
# map.delete("a") #=> [100]
|
119
115
|
def delete(key, value = nil)
|
120
116
|
if value
|
121
|
-
|
117
|
+
@hash[key].delete(value)
|
122
118
|
else
|
123
|
-
|
119
|
+
@hash.delete(key)
|
124
120
|
end
|
125
121
|
end
|
126
122
|
|
@@ -157,15 +153,9 @@ class Multimap < Hash
|
|
157
153
|
#
|
158
154
|
# a is [100]
|
159
155
|
# b is [200, 300]
|
160
|
-
def each_association
|
161
|
-
|
156
|
+
def each_association(&block)
|
157
|
+
@hash.each_pair(&block)
|
162
158
|
end
|
163
|
-
#--
|
164
|
-
# Ignore alias_method since the definition above serves
|
165
|
-
# as its documentation.
|
166
|
-
#++
|
167
|
-
remove_method :each_association
|
168
|
-
module_eval "alias_method :each_association, :each_pair"
|
169
159
|
|
170
160
|
# call-seq:
|
171
161
|
# map.each_container { |container| block } => map
|
@@ -248,6 +238,24 @@ class Multimap < Hash
|
|
248
238
|
end
|
249
239
|
end
|
250
240
|
|
241
|
+
def ==(other) #:nodoc:
|
242
|
+
case other
|
243
|
+
when Multimap
|
244
|
+
@hash == other._internal_hash
|
245
|
+
else
|
246
|
+
@hash == other
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def eql?(other) #:nodoc:
|
251
|
+
case other
|
252
|
+
when Multimap
|
253
|
+
@hash.eql?(other._internal_hash)
|
254
|
+
else
|
255
|
+
@hash.eql?(other)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
251
259
|
def freeze #:nodoc:
|
252
260
|
each_container { |container| container.freeze }
|
253
261
|
default.freeze
|
@@ -283,6 +291,21 @@ class Multimap < Hash
|
|
283
291
|
invert[value]
|
284
292
|
end
|
285
293
|
|
294
|
+
def delete_if(&block) #:nodoc:
|
295
|
+
@hash.delete_if(&block)
|
296
|
+
self
|
297
|
+
end
|
298
|
+
|
299
|
+
def reject(&block) #:nodoc:
|
300
|
+
dup.delete_if(&block)
|
301
|
+
end
|
302
|
+
|
303
|
+
def reject!(&block) #:nodoc:
|
304
|
+
old_size = size
|
305
|
+
delete_if(&block)
|
306
|
+
old_size == size ? nil : self
|
307
|
+
end
|
308
|
+
|
286
309
|
# call-seq:
|
287
310
|
# map.replace(other_map) => map
|
288
311
|
#
|
@@ -295,11 +318,11 @@ class Multimap < Hash
|
|
295
318
|
def replace(other)
|
296
319
|
case other
|
297
320
|
when Array
|
298
|
-
|
321
|
+
@hash.replace(self.class[self.default, *other])
|
299
322
|
when Hash
|
300
|
-
|
323
|
+
@hash.replace(self.class[self.default, other])
|
301
324
|
when self.class
|
302
|
-
|
325
|
+
@hash.replace(other)
|
303
326
|
else
|
304
327
|
raise ArgumentError
|
305
328
|
end
|
@@ -333,6 +356,12 @@ class Multimap < Hash
|
|
333
356
|
keys
|
334
357
|
end
|
335
358
|
|
359
|
+
# Returns true if the given key is present in Multimap.
|
360
|
+
def include?(key)
|
361
|
+
keys.include?(key)
|
362
|
+
end
|
363
|
+
alias_method :member?, :include?
|
364
|
+
|
336
365
|
# call-seq:
|
337
366
|
# map.length => fixnum
|
338
367
|
# map.size => fixnum
|
@@ -426,7 +455,7 @@ class Multimap < Hash
|
|
426
455
|
# map = Multimap["a" => 100, "b" => [200, 300]]
|
427
456
|
# map.to_hash #=> { "a" => [100], "b" => [200, 300] }
|
428
457
|
def to_hash
|
429
|
-
dup
|
458
|
+
@hash.dup
|
430
459
|
end
|
431
460
|
|
432
461
|
# call-seq:
|
@@ -457,11 +486,20 @@ class Multimap < Hash
|
|
457
486
|
values
|
458
487
|
end
|
459
488
|
|
489
|
+
# Return an array containing the values associated with the given keys.
|
490
|
+
def values_at(*keys)
|
491
|
+
@hash.values_at(*keys)
|
492
|
+
end
|
493
|
+
|
460
494
|
protected
|
495
|
+
def _internal_hash #:nodoc:
|
496
|
+
@hash
|
497
|
+
end
|
498
|
+
|
461
499
|
def update_container(key) #:nodoc:
|
462
|
-
container =
|
500
|
+
container = @hash[key]
|
463
501
|
container = container.dup if container.equal?(default)
|
464
502
|
container = yield(container)
|
465
|
-
|
503
|
+
@hash[key] = container
|
466
504
|
end
|
467
505
|
end
|
@@ -45,7 +45,7 @@ class NestedMultimap < Multimap
|
|
45
45
|
# map["a"] #=> [100, 300]
|
46
46
|
# map["c"] #=> [300]
|
47
47
|
def <<(value)
|
48
|
-
|
48
|
+
@hash.each_pair { |_, container| container << value }
|
49
49
|
self.default << value
|
50
50
|
self
|
51
51
|
end
|
@@ -59,7 +59,7 @@ class NestedMultimap < Multimap
|
|
59
59
|
def [](*keys)
|
60
60
|
i, l, r, k = 0, keys.length, self, self.class
|
61
61
|
while r.is_a?(k)
|
62
|
-
r = i < l ? r.
|
62
|
+
r = i < l ? r._internal_hash[keys[i]] : r.default
|
63
63
|
i += 1
|
64
64
|
end
|
65
65
|
r
|
@@ -83,7 +83,7 @@ class NestedMultimap < Multimap
|
|
83
83
|
# ["a", "b"] is [100, 101, 102]
|
84
84
|
# "c" is [200]
|
85
85
|
def each_association
|
86
|
-
super do |key, container|
|
86
|
+
super() do |key, container|
|
87
87
|
if container.respond_to?(:each_association)
|
88
88
|
container.each_association do |nested_key, value|
|
89
89
|
yield [key, nested_key].flatten, value
|
@@ -122,7 +122,7 @@ class NestedMultimap < Multimap
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
|
125
|
+
@hash.each_pair { |_, container| each_container.call(container) }
|
126
126
|
each_container.call(default)
|
127
127
|
|
128
128
|
self
|
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.2.
|
4
|
+
version: 0.2.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-11-
|
12
|
+
date: 2009-11-29 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|