http_router 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.gitignore +2 -1
  2. data/Rakefile +7 -5
  3. data/benchmarks/gen2.rb +1 -1
  4. data/benchmarks/rack_mount.rb +8 -14
  5. data/examples/rack_mapper.ru +12 -13
  6. data/examples/variable_with_regex.ru +1 -1
  7. data/http_router.gemspec +1 -1
  8. data/lib/http_router.rb +159 -62
  9. data/lib/http_router/generation_helper.rb +29 -0
  10. data/lib/http_router/generator.rb +150 -0
  11. data/lib/http_router/node.rb +27 -17
  12. data/lib/http_router/node/abstract_request_node.rb +31 -0
  13. data/lib/http_router/node/host.rb +9 -0
  14. data/lib/http_router/node/lookup.rb +8 -10
  15. data/lib/http_router/node/path.rb +23 -38
  16. data/lib/http_router/node/request_method.rb +16 -0
  17. data/lib/http_router/node/root.rb +104 -10
  18. data/lib/http_router/node/scheme.rb +9 -0
  19. data/lib/http_router/node/user_agent.rb +9 -0
  20. data/lib/http_router/regex_route_generation.rb +10 -0
  21. data/lib/http_router/request.rb +7 -17
  22. data/lib/http_router/response.rb +4 -0
  23. data/lib/http_router/route.rb +16 -277
  24. data/lib/http_router/route_helper.rb +126 -0
  25. data/lib/http_router/util.rb +1 -37
  26. data/lib/http_router/version.rb +1 -1
  27. data/test/common/generate.txt +1 -1
  28. data/test/generation.rb +15 -11
  29. data/test/generic.rb +2 -3
  30. data/test/helper.rb +15 -10
  31. data/test/rack/test_route.rb +0 -5
  32. data/test/test_misc.rb +50 -40
  33. data/test/test_mounting.rb +27 -26
  34. data/test/test_recognition.rb +1 -76
  35. metadata +104 -161
  36. data/.rspec +0 -1
  37. data/lib/http_router/node/arbitrary.rb +0 -30
  38. data/lib/http_router/node/request.rb +0 -52
  39. data/lib/http_router/rack.rb +0 -19
  40. data/lib/http_router/rack/builder.rb +0 -61
  41. data/lib/http_router/rack/url_map.rb +0 -16
  42. data/lib/http_router/regex_route.rb +0 -39
metadata CHANGED
@@ -1,187 +1,135 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: http_router
3
- version: !ruby/object:Gem::Version
4
- hash: 51
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.11.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 10
9
- - 2
10
- version: 0.10.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Joshua Hull
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-09 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rack
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70277157558240 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 23
30
- segments:
31
- - 1
32
- - 0
33
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 1.0.0
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: url_mount
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70277157558240
25
+ - !ruby/object:Gem::Dependency
26
+ name: url_mount
27
+ requirement: &70277157557460 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
29
+ requirements:
43
30
  - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 21
46
- segments:
47
- - 0
48
- - 2
49
- - 1
31
+ - !ruby/object:Gem::Version
50
32
  version: 0.2.1
51
33
  type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: minitest
55
34
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70277157557460
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ requirement: &70277157556860 !ruby/object:Gem::Requirement
57
39
  none: false
58
- requirements:
40
+ requirements:
59
41
  - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 15
62
- segments:
63
- - 2
64
- - 0
65
- - 0
42
+ - !ruby/object:Gem::Version
66
43
  version: 2.0.0
67
44
  type: :development
68
- version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: code_stats
71
45
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70277157556860
47
+ - !ruby/object:Gem::Dependency
48
+ name: code_stats
49
+ requirement: &70277157556280 !ruby/object:Gem::Requirement
73
50
  none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- hash: 3
78
- segments:
79
- - 0
80
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
81
55
  type: :development
82
- version_requirements: *id004
83
- - !ruby/object:Gem::Dependency
84
- name: rake
85
56
  prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *70277157556280
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: &70277157555580 !ruby/object:Gem::Requirement
87
61
  none: false
88
- requirements:
62
+ requirements:
89
63
  - - ~>
90
- - !ruby/object:Gem::Version
91
- hash: 49
92
- segments:
93
- - 0
94
- - 8
95
- - 7
64
+ - !ruby/object:Gem::Version
96
65
  version: 0.8.7
97
66
  type: :development
98
- version_requirements: *id005
99
- - !ruby/object:Gem::Dependency
100
- name: rbench
101
67
  prerelease: false
102
- requirement: &id006 !ruby/object:Gem::Requirement
68
+ version_requirements: *70277157555580
69
+ - !ruby/object:Gem::Dependency
70
+ name: rbench
71
+ requirement: &70277157571180 !ruby/object:Gem::Requirement
103
72
  none: false
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- hash: 3
108
- segments:
109
- - 0
110
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
111
77
  type: :development
112
- version_requirements: *id006
113
- - !ruby/object:Gem::Dependency
114
- name: json
115
78
  prerelease: false
116
- requirement: &id007 !ruby/object:Gem::Requirement
79
+ version_requirements: *70277157571180
80
+ - !ruby/object:Gem::Dependency
81
+ name: json
82
+ requirement: &70277157570560 !ruby/object:Gem::Requirement
117
83
  none: false
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- hash: 3
122
- segments:
123
- - 0
124
- version: "0"
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
125
88
  type: :development
126
- version_requirements: *id007
127
- - !ruby/object:Gem::Dependency
128
- name: phocus
129
89
  prerelease: false
130
- requirement: &id008 !ruby/object:Gem::Requirement
90
+ version_requirements: *70277157570560
91
+ - !ruby/object:Gem::Dependency
92
+ name: phocus
93
+ requirement: &70277157570000 !ruby/object:Gem::Requirement
131
94
  none: false
132
- requirements:
133
- - - ">="
134
- - !ruby/object:Gem::Version
135
- hash: 3
136
- segments:
137
- - 0
138
- version: "0"
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
139
99
  type: :development
140
- version_requirements: *id008
141
- - !ruby/object:Gem::Dependency
142
- name: bundler
143
100
  prerelease: false
144
- requirement: &id009 !ruby/object:Gem::Requirement
101
+ version_requirements: *70277157570000
102
+ - !ruby/object:Gem::Dependency
103
+ name: bundler
104
+ requirement: &70277157569360 !ruby/object:Gem::Requirement
145
105
  none: false
146
- requirements:
147
- - - ~>
148
- - !ruby/object:Gem::Version
149
- hash: 23
150
- segments:
151
- - 1
152
- - 0
153
- - 0
154
- version: 1.0.0
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
155
110
  type: :development
156
- version_requirements: *id009
157
- - !ruby/object:Gem::Dependency
158
- name: thin
159
111
  prerelease: false
160
- requirement: &id010 !ruby/object:Gem::Requirement
112
+ version_requirements: *70277157569360
113
+ - !ruby/object:Gem::Dependency
114
+ name: thin
115
+ requirement: &70277157568620 !ruby/object:Gem::Requirement
161
116
  none: false
162
- requirements:
163
- - - "="
164
- - !ruby/object:Gem::Version
165
- hash: 15
166
- segments:
167
- - 1
168
- - 2
169
- - 8
117
+ requirements:
118
+ - - =
119
+ - !ruby/object:Gem::Version
170
120
  version: 1.2.8
171
121
  type: :development
172
- version_requirements: *id010
122
+ prerelease: false
123
+ version_requirements: *70277157568620
173
124
  description: This library allows you to recognize and build URLs in a Rack application.
174
125
  email: joshbuddy@gmail.com
175
126
  executables: []
176
-
177
127
  extensions: []
178
-
179
- extra_rdoc_files:
128
+ extra_rdoc_files:
180
129
  - README.md
181
130
  - LICENSE
182
- files:
131
+ files:
183
132
  - .gitignore
184
- - .rspec
185
133
  - Gemfile
186
134
  - LICENSE
187
135
  - README.md
@@ -209,25 +157,28 @@ files:
209
157
  - js/test/test.coffee
210
158
  - js/test/test.js
211
159
  - lib/http_router.rb
160
+ - lib/http_router/generation_helper.rb
161
+ - lib/http_router/generator.rb
212
162
  - lib/http_router/node.rb
213
- - lib/http_router/node/arbitrary.rb
163
+ - lib/http_router/node/abstract_request_node.rb
214
164
  - lib/http_router/node/free_regex.rb
215
165
  - lib/http_router/node/glob.rb
216
166
  - lib/http_router/node/glob_regex.rb
167
+ - lib/http_router/node/host.rb
217
168
  - lib/http_router/node/lookup.rb
218
169
  - lib/http_router/node/path.rb
219
170
  - lib/http_router/node/regex.rb
220
- - lib/http_router/node/request.rb
171
+ - lib/http_router/node/request_method.rb
221
172
  - lib/http_router/node/root.rb
173
+ - lib/http_router/node/scheme.rb
222
174
  - lib/http_router/node/spanning_regex.rb
175
+ - lib/http_router/node/user_agent.rb
223
176
  - lib/http_router/node/variable.rb
224
- - lib/http_router/rack.rb
225
- - lib/http_router/rack/builder.rb
226
- - lib/http_router/rack/url_map.rb
227
- - lib/http_router/regex_route.rb
177
+ - lib/http_router/regex_route_generation.rb
228
178
  - lib/http_router/request.rb
229
179
  - lib/http_router/response.rb
230
180
  - lib/http_router/route.rb
181
+ - lib/http_router/route_helper.rb
231
182
  - lib/http_router/util.rb
232
183
  - lib/http_router/version.rb
233
184
  - test/common/generate.txt
@@ -242,41 +193,32 @@ files:
242
193
  - test/test_mounting.rb
243
194
  - test/test_recognition.rb
244
195
  - test/test_trailing_slash.rb
245
- has_rdoc: true
246
196
  homepage: http://github.com/joshbuddy/http_router
247
197
  licenses: []
248
-
249
198
  post_install_message:
250
- rdoc_options:
199
+ rdoc_options:
251
200
  - --charset=UTF-8
252
- require_paths:
201
+ require_paths:
253
202
  - lib
254
- required_ruby_version: !ruby/object:Gem::Requirement
203
+ required_ruby_version: !ruby/object:Gem::Requirement
255
204
  none: false
256
- requirements:
257
- - - ">="
258
- - !ruby/object:Gem::Version
259
- hash: 3
260
- segments:
261
- - 0
262
- version: "0"
263
- required_rubygems_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ! '>='
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ required_rubygems_version: !ruby/object:Gem::Requirement
264
210
  none: false
265
- requirements:
266
- - - ">="
267
- - !ruby/object:Gem::Version
268
- hash: 3
269
- segments:
270
- - 0
271
- version: "0"
211
+ requirements:
212
+ - - ! '>='
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
272
215
  requirements: []
273
-
274
216
  rubyforge_project: http_router
275
- rubygems_version: 1.6.2
217
+ rubygems_version: 1.8.15
276
218
  signing_key:
277
219
  specification_version: 3
278
220
  summary: A kick-ass HTTP router for use in Rack
279
- test_files:
221
+ test_files:
280
222
  - test/common/generate.txt
281
223
  - test/common/http_recognize.txt
282
224
  - test/common/recognize.txt
@@ -289,3 +231,4 @@ test_files:
289
231
  - test/test_mounting.rb
290
232
  - test/test_recognition.rb
291
233
  - test/test_trailing_slash.rb
234
+ has_rdoc:
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --colour
@@ -1,30 +0,0 @@
1
- class HttpRouter
2
- class Node
3
- class Arbitrary < Node
4
- attr_reader :allow_partial, :blk, :param_names
5
-
6
- def initialize(router, parent, sallow_partial, blk, param_names)
7
- @allow_partial, @blk, @param_names = allow_partial, blk, param_names
8
- super(router, parent)
9
- end
10
-
11
- def usable?(other)
12
- other.class == self.class && other.allow_partial == allow_partial && other.blk == blk && other.param_names == param_names
13
- end
14
-
15
- def to_code
16
- b, method_name = @blk, :"blk_#{root.next_counter}"
17
- inject_root_methods { define_method(method_name) { b } }
18
- "#{"if request.path_finished?" unless @allow_partial}
19
- request.continue = proc { |state|
20
- if state
21
- #{super}
22
- end
23
- }
24
- #{method_name}[request, #{@param_names.nil? || @param_names.empty? ? '{}' : "Hash[#{@param_names.inspect}.zip(request.params)]"}]
25
- request.continue = nil
26
- #{"end" unless @allow_partial}"
27
- end
28
- end
29
- end
30
- end
@@ -1,52 +0,0 @@
1
- class HttpRouter
2
- class Node
3
- class Request < Node
4
- VALID_HTTP_VERBS = %w[HEAD GET DELETE POST PUT OPTIONS PATCH TRACE CONNECT]
5
-
6
- attr_reader :request_method, :opts
7
-
8
- def initialize(router, parent, opts)
9
- opts.each do |k, v|
10
- v = [v] unless v.is_a?(Array)
11
- case k
12
- when :request_method
13
- v.map!{|val| val.to_s.upcase}
14
- v.all?{|m| VALID_HTTP_VERBS.include?(m)} or raise InvalidRequestValueError, "Invalid value for request_method #{v.inspect}"
15
- v.each{|val| router.known_methods << val}
16
- end
17
- opts[k] = v
18
- end
19
- @opts = opts
20
- @opts[:request_method].each { |m| router.known_methods << m } if @opts.key?(:request_method)
21
- super(router, parent)
22
- end
23
-
24
- def usable?(other)
25
- other.class == self.class && other.opts == opts
26
- end
27
-
28
- def to_code
29
- code = "if "
30
- code << @opts.map do |k,v|
31
- case v.size
32
- when 1 then to_code_condition(k, v.first)
33
- else "(#{v.map{|vv| to_code_condition(k, vv)}.join(' or ')})"
34
- end
35
- end * ' and '
36
- code << "\n #{super}\nend"
37
- end
38
-
39
- def inspect_label
40
- "#{self.class.name.split("::").last} #{opts.inspect} (#{@matchers.size} matchers)"
41
- end
42
-
43
- private
44
- def to_code_condition(k, v)
45
- case v
46
- when String then "#{v.inspect} == request.rack_request.#{k}"
47
- else "#{v.inspect} === request.rack_request.#{k}"
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,19 +0,0 @@
1
- class HttpRouter
2
- module Rack
3
- autoload :URLMap, 'http_router/rack/url_map'
4
- autoload :Builder, 'http_router/rack/builder'
5
- autoload :BuilderMixin, 'http_router/rack/builder'
6
-
7
- # Monkey-patches Rack::Builder to use HttpRouter.
8
- # See examples/rack_mapper.rb
9
- def self.override_rack_builder!
10
- ::Rack::Builder.class_eval("remove_method :map; include HttpRouter::Rack::BuilderMixin")
11
- end
12
-
13
- # Monkey-patches Rack::URLMap to use HttpRouter.
14
- # See examples/rack_mapper.rb
15
- def self.override_rack_urlmap!
16
- ::Rack.class_eval("OriginalURLMap = URLMap; HttpRouterURLMap = HttpRouter::Rack::URLMap; remove_const :URLMap; URLMap = HttpRouterURLMap")
17
- end
18
- end
19
- end