rack-mount 0.0.1 → 0.8.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.
Files changed (43) hide show
  1. data/README.rdoc +12 -4
  2. data/lib/rack/mount/analysis/histogram.rb +55 -6
  3. data/lib/rack/mount/analysis/splitting.rb +103 -89
  4. data/lib/rack/mount/code_generation.rb +120 -0
  5. data/lib/rack/mount/generatable_regexp.rb +95 -48
  6. data/lib/rack/mount/multimap.rb +84 -41
  7. data/lib/rack/mount/prefix.rb +13 -8
  8. data/lib/rack/mount/regexp_with_named_groups.rb +27 -7
  9. data/lib/rack/mount/route.rb +75 -18
  10. data/lib/rack/mount/route_set.rb +308 -22
  11. data/lib/rack/mount/strexp/parser.rb +160 -0
  12. data/lib/rack/mount/strexp/tokenizer.rb +83 -0
  13. data/lib/rack/mount/strexp.rb +54 -79
  14. data/lib/rack/mount/utils.rb +65 -174
  15. data/lib/rack/mount/vendor/regin/regin/alternation.rb +40 -0
  16. data/lib/rack/mount/vendor/regin/regin/anchor.rb +4 -0
  17. data/lib/rack/mount/vendor/regin/regin/atom.rb +54 -0
  18. data/lib/rack/mount/vendor/regin/regin/character.rb +51 -0
  19. data/lib/rack/mount/vendor/regin/regin/character_class.rb +50 -0
  20. data/lib/rack/mount/vendor/regin/regin/collection.rb +77 -0
  21. data/lib/rack/mount/vendor/regin/regin/expression.rb +126 -0
  22. data/lib/rack/mount/vendor/regin/regin/group.rb +90 -0
  23. data/lib/rack/mount/vendor/regin/regin/options.rb +55 -0
  24. data/lib/rack/mount/vendor/regin/regin/parser.rb +546 -0
  25. data/lib/rack/mount/vendor/regin/regin/tokenizer.rb +255 -0
  26. data/lib/rack/mount/vendor/regin/regin/version.rb +3 -0
  27. data/lib/rack/mount/vendor/regin/regin.rb +75 -0
  28. data/lib/rack/mount/version.rb +3 -0
  29. data/lib/rack/mount.rb +13 -17
  30. metadata +88 -35
  31. data/lib/rack/mount/analysis/frequency.rb +0 -51
  32. data/lib/rack/mount/const.rb +0 -45
  33. data/lib/rack/mount/exceptions.rb +0 -3
  34. data/lib/rack/mount/generation/route.rb +0 -57
  35. data/lib/rack/mount/generation/route_set.rb +0 -163
  36. data/lib/rack/mount/meta_method.rb +0 -104
  37. data/lib/rack/mount/mixover.rb +0 -47
  38. data/lib/rack/mount/recognition/code_generation.rb +0 -99
  39. data/lib/rack/mount/recognition/route.rb +0 -59
  40. data/lib/rack/mount/recognition/route_set.rb +0 -88
  41. data/lib/rack/mount/vendor/multimap/multimap.rb +0 -466
  42. data/lib/rack/mount/vendor/multimap/multiset.rb +0 -153
  43. data/lib/rack/mount/vendor/multimap/nested_multimap.rb +0 -156
@@ -1,156 +0,0 @@
1
- require 'multimap'
2
-
3
- # NestedMultimap allows values to be assoicated with a nested
4
- # set of keys.
5
- class NestedMultimap < Multimap
6
- # call-seq:
7
- # multimap[*keys] = value => value
8
- # multimap.store(*keys, value) => value
9
- #
10
- # Associates the value given by <i>value</i> with multiple key
11
- # given by <i>keys</i>.
12
- #
13
- # map = NestedMultimap.new
14
- # map["a"] = 100
15
- # map["a", "b"] = 101
16
- # map["a"] = 102
17
- # map #=> {"a"=>{"b"=>[100, 101, 102], default => [100, 102]}}
18
- def store(*args)
19
- keys = args
20
- value = args.pop
21
-
22
- raise ArgumentError, 'wrong number of arguments (1 for 2)' unless value
23
-
24
- if keys.length > 1
25
- update_container(keys.shift) do |container|
26
- container = self.class.new(container) unless container.is_a?(self.class)
27
- container[*keys] = value
28
- container
29
- end
30
- elsif keys.length == 1
31
- super(keys.first, value)
32
- else
33
- self << value
34
- end
35
- end
36
- alias_method :[]=, :store
37
-
38
- # call-seq:
39
- # multimap << obj => multimap
40
- #
41
- # Pushes the given object on to the end of all the containers.
42
- #
43
- # map = NestedMultimap["a" => [100], "b" => [200, 300]]
44
- # map << 300
45
- # map["a"] #=> [100, 300]
46
- # map["c"] #=> [300]
47
- def <<(value)
48
- hash_each_pair { |_, container| container << value }
49
- self.default << value
50
- self
51
- end
52
-
53
- # call-seq:
54
- # multimap[*keys] => value
55
- # multimap[key1, key2, key3] => value
56
- #
57
- # Retrieves the <i>value</i> object corresponding to the
58
- # <i>*keys</i> object.
59
- def [](*keys)
60
- i, l, r, k = 0, keys.length, self, self.class
61
- while r.is_a?(k)
62
- r = i < l ? r.hash_aref(keys[i]) : r.default
63
- i += 1
64
- end
65
- r
66
- end
67
-
68
- # call-seq:
69
- # multimap.each_association { |key, container| block } => multimap
70
- #
71
- # Calls <i>block</i> once for each key/container in <i>map</i>, passing
72
- # the key and container to the block as parameters.
73
- #
74
- # map = NestedMultimap.new
75
- # map["a"] = 100
76
- # map["a", "b"] = 101
77
- # map["a"] = 102
78
- # map["c"] = 200
79
- # map.each_association { |key, container| puts "#{key} is #{container}" }
80
- #
81
- # <em>produces:</em>
82
- #
83
- # ["a", "b"] is [100, 101, 102]
84
- # "c" is [200]
85
- def each_association
86
- super do |key, container|
87
- if container.respond_to?(:each_association)
88
- container.each_association do |nested_key, value|
89
- yield [key, nested_key].flatten, value
90
- end
91
- else
92
- yield key, container
93
- end
94
- end
95
- end
96
-
97
- # call-seq:
98
- # multimap.each_container_with_default { |container| block } => map
99
- #
100
- # Calls <i>block</i> for every container in <i>map</i> including
101
- # the default, passing the container as a parameter.
102
- #
103
- # map = NestedMultimap.new
104
- # map["a"] = 100
105
- # map["a", "b"] = 101
106
- # map["a"] = 102
107
- # map.each_container_with_default { |container| puts container }
108
- #
109
- # <em>produces:</em>
110
- #
111
- # [100, 101, 102]
112
- # [100, 102]
113
- # []
114
- def each_container_with_default
115
- each_container = Proc.new do |container|
116
- if container.respond_to?(:each_container_with_default)
117
- container.each_container_with_default do |value|
118
- yield value
119
- end
120
- else
121
- yield container
122
- end
123
- end
124
-
125
- hash_each_pair { |_, container| each_container.call(container) }
126
- each_container.call(default)
127
-
128
- self
129
- end
130
-
131
- # call-seq:
132
- # multimap.containers_with_default => array
133
- #
134
- # Returns a new array populated with all the containers from
135
- # <i>map</i> including the default.
136
- #
137
- # map = NestedMultimap.new
138
- # map["a"] = 100
139
- # map["a", "b"] = 101
140
- # map["a"] = 102
141
- # map.containers_with_default #=> [[100, 101, 102], [100, 102], []]
142
- def containers_with_default
143
- containers = []
144
- each_container_with_default { |container| containers << container }
145
- containers
146
- end
147
-
148
- def inspect #:nodoc:
149
- super.gsub(/\}$/, ", default => #{default.inspect}}")
150
- end
151
- end
152
-
153
- begin
154
- require 'nested_multimap_ext'
155
- rescue LoadError
156
- end