http_router 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,6 +14,16 @@ class HttpRouter
14
14
  other.class == self.class
15
15
  end
16
16
 
17
+ def inspect_matchers_body
18
+ @map.map { |key, values|
19
+ ins = "#{' ' * depth}when #{key.inspect}:\n"
20
+ ins << values.map{|v| v.inspect}.join("\n") }.join("\n")
21
+ end
22
+
23
+ def inspect_label
24
+ "#{self.class.name}"
25
+ end
26
+
17
27
  def to_code
18
28
  lookup_ivar = inject_root_ivar(@map)
19
29
  method_prefix = "lookup_#{root.next_counter} "
@@ -53,6 +53,10 @@ class HttpRouter
53
53
  other == self
54
54
  end
55
55
 
56
+ def inspect_label
57
+ "Path: #{original_path.inspect} for route #{route.named || 'unnamed route'} to #{route.dest.inspect}"
58
+ end
59
+
56
60
  private
57
61
  def raw_url(args, options)
58
62
  raise InvalidRouteException
@@ -36,6 +36,10 @@ class HttpRouter
36
36
  code << "\n #{super}\nend"
37
37
  end
38
38
 
39
+ def inspect_label
40
+ "#{self.class.name.split("::").last} #{opts.inspect} (#{@matchers.size} matchers)"
41
+ end
42
+
39
43
  private
40
44
  def to_code_condition(k, v)
41
45
  case v
@@ -28,6 +28,14 @@ class HttpRouter
28
28
  name
29
29
  end
30
30
 
31
+ def depth
32
+ 0
33
+ end
34
+
35
+ def inspect_label
36
+ "Root (#{@matchers.size} matchers)"
37
+ end
38
+
31
39
  private
32
40
  def compile
33
41
  root.extend(root.methods_module)
@@ -64,6 +64,27 @@ class HttpRouter
64
64
  false
65
65
  end
66
66
 
67
+ def inspect
68
+ ins = "#{' ' * depth}#{inspect_label}"
69
+ body = inspect_matchers_body
70
+ unless body =~ /^\s*$/
71
+ ins << "\n" << body
72
+ end
73
+ ins
74
+ end
75
+
76
+ def inspect_label
77
+ "#{self.class.name.split("::").last} (#{@matchers.size} matchers)"
78
+ end
79
+
80
+ def inspect_matchers_body
81
+ @matchers.map{ |m| m.inspect}.join("\n")
82
+ end
83
+
84
+ def depth
85
+ @parent.send(:depth) + 1
86
+ end
87
+
67
88
  private
68
89
  def inject_root_methods(code = nil, &blk)
69
90
  code ? root.methods_module.module_eval(code) : root.methods_module.module_eval(&blk)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  class HttpRouter #:nodoc
3
- VERSION = '0.9.5'
3
+ VERSION = '0.9.6'
4
4
  end
data/lib/http_router.rb CHANGED
@@ -217,6 +217,15 @@ class HttpRouter
217
217
  supported_methods.empty? ? (perform_call ? @default_app.call(env) : nil) : [405, {'Allow' => supported_methods.sort.join(", ")}, []]
218
218
  end
219
219
 
220
+ def to_s
221
+ "#<HttpRouter:0x#{object_id.to_s(16)} number of routes (#{routes.size}) ignore_trailing_slash? (#{ignore_trailing_slash?}) redirect_trailing_slash? (#{redirect_trailing_slash?}) known_methods (#{known_methods.to_a.join(', ')})>"
222
+ end
223
+
224
+ def inspect
225
+ head = to_s
226
+ "#{to_s}\n#{'=' * head.size}\n#{@root.inspect}"
227
+ end
228
+
220
229
  private
221
230
  def add_with_request_method(path, method, opts = {}, &app)
222
231
  route = add(path, opts).send(method.to_sym)
data/test/test_misc.rb CHANGED
@@ -72,4 +72,14 @@ class TestMisc < MiniTest::Unit::TestCase
72
72
  assert methods.include?(:rewrite_partial_path_info)
73
73
  assert methods.include?(:rewrite_path_info)
74
74
  end
75
+
76
+ def test_to_s_and_inspect
77
+ router = HttpRouter.new
78
+ router.add('/').to(:test)
79
+ router.add('/test').to(:test2)
80
+ router.post('/test').to(:test3)
81
+ assert router.to_s.match(/^#<HttpRouter:0x[0-9a-f]+ number of routes \(3\) ignore_trailing_slash\? \(true\) redirect_trailing_slash\? \(false\) known_methods \(POST\)>$/)
82
+ assert router.inspect.match(/^#<HttpRouter:0x[0-9a-f]+ number of routes \(3\) ignore_trailing_slash\? \(true\) redirect_trailing_slash\? \(false\) known_methods \(POST\)>/)
83
+ assert router.inspect.match(/Path: "\/test" for route unnamed route to :test3/)
84
+ end
75
85
  end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_router
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 55
4
5
  prerelease:
5
- version: 0.9.5
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 6
10
+ version: 0.9.6
6
11
  platform: ruby
7
12
  authors:
8
13
  - Joshua Hull
@@ -10,119 +15,161 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-07-30 00:00:00 -07:00
18
+ date: 2011-08-03 00:00:00 -07:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
- name: rack
18
22
  prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
20
24
  none: false
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ hash: 23
29
+ segments:
30
+ - 1
31
+ - 0
32
+ - 0
24
33
  version: 1.0.0
34
+ requirement: *id001
35
+ name: rack
25
36
  type: :runtime
26
- version_requirements: *id001
27
37
  - !ruby/object:Gem::Dependency
28
- name: url_mount
29
38
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
31
40
  none: false
32
41
  requirements:
33
42
  - - ~>
34
43
  - !ruby/object:Gem::Version
44
+ hash: 21
45
+ segments:
46
+ - 0
47
+ - 2
48
+ - 1
35
49
  version: 0.2.1
50
+ requirement: *id002
51
+ name: url_mount
36
52
  type: :runtime
37
- version_requirements: *id002
38
53
  - !ruby/object:Gem::Dependency
39
- name: minitest
40
54
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
42
56
  none: false
43
57
  requirements:
44
58
  - - ~>
45
59
  - !ruby/object:Gem::Version
60
+ hash: 15
61
+ segments:
62
+ - 2
63
+ - 0
64
+ - 0
46
65
  version: 2.0.0
66
+ requirement: *id003
67
+ name: minitest
47
68
  type: :development
48
- version_requirements: *id003
49
69
  - !ruby/object:Gem::Dependency
50
- name: code_stats
51
70
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
53
72
  none: false
54
73
  requirements:
55
74
  - - ">="
56
75
  - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
57
79
  version: "0"
80
+ requirement: *id004
81
+ name: code_stats
58
82
  type: :development
59
- version_requirements: *id004
60
83
  - !ruby/object:Gem::Dependency
61
- name: rake
62
84
  prerelease: false
63
- requirement: &id005 !ruby/object:Gem::Requirement
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
64
86
  none: false
65
87
  requirements:
66
88
  - - ~>
67
89
  - !ruby/object:Gem::Version
90
+ hash: 49
91
+ segments:
92
+ - 0
93
+ - 8
94
+ - 7
68
95
  version: 0.8.7
96
+ requirement: *id005
97
+ name: rake
69
98
  type: :development
70
- version_requirements: *id005
71
99
  - !ruby/object:Gem::Dependency
72
- name: rbench
73
100
  prerelease: false
74
- requirement: &id006 !ruby/object:Gem::Requirement
101
+ version_requirements: &id006 !ruby/object:Gem::Requirement
75
102
  none: false
76
103
  requirements:
77
104
  - - ">="
78
105
  - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
79
109
  version: "0"
110
+ requirement: *id006
111
+ name: rbench
80
112
  type: :development
81
- version_requirements: *id006
82
113
  - !ruby/object:Gem::Dependency
83
- name: json
84
114
  prerelease: false
85
- requirement: &id007 !ruby/object:Gem::Requirement
115
+ version_requirements: &id007 !ruby/object:Gem::Requirement
86
116
  none: false
87
117
  requirements:
88
118
  - - ">="
89
119
  - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
90
123
  version: "0"
124
+ requirement: *id007
125
+ name: json
91
126
  type: :development
92
- version_requirements: *id007
93
127
  - !ruby/object:Gem::Dependency
94
- name: phocus
95
128
  prerelease: false
96
- requirement: &id008 !ruby/object:Gem::Requirement
129
+ version_requirements: &id008 !ruby/object:Gem::Requirement
97
130
  none: false
98
131
  requirements:
99
132
  - - ">="
100
133
  - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
101
137
  version: "0"
138
+ requirement: *id008
139
+ name: phocus
102
140
  type: :development
103
- version_requirements: *id008
104
141
  - !ruby/object:Gem::Dependency
105
- name: bundler
106
142
  prerelease: false
107
- requirement: &id009 !ruby/object:Gem::Requirement
143
+ version_requirements: &id009 !ruby/object:Gem::Requirement
108
144
  none: false
109
145
  requirements:
110
146
  - - ~>
111
147
  - !ruby/object:Gem::Version
148
+ hash: 23
149
+ segments:
150
+ - 1
151
+ - 0
152
+ - 0
112
153
  version: 1.0.0
154
+ requirement: *id009
155
+ name: bundler
113
156
  type: :development
114
- version_requirements: *id009
115
157
  - !ruby/object:Gem::Dependency
116
- name: thin
117
158
  prerelease: false
118
- requirement: &id010 !ruby/object:Gem::Requirement
159
+ version_requirements: &id010 !ruby/object:Gem::Requirement
119
160
  none: false
120
161
  requirements:
121
162
  - - "="
122
163
  - !ruby/object:Gem::Version
164
+ hash: 15
165
+ segments:
166
+ - 1
167
+ - 2
168
+ - 8
123
169
  version: 1.2.8
170
+ requirement: *id010
171
+ name: thin
124
172
  type: :development
125
- version_requirements: *id010
126
173
  description: This library allows you to recognize and build URLs in a Rack application.
127
174
  email: joshbuddy@gmail.com
128
175
  executables: []
@@ -209,12 +256,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
256
  requirements:
210
257
  - - ">="
211
258
  - !ruby/object:Gem::Version
259
+ hash: 3
260
+ segments:
261
+ - 0
212
262
  version: "0"
213
263
  required_rubygems_version: !ruby/object:Gem::Requirement
214
264
  none: false
215
265
  requirements:
216
266
  - - ">="
217
267
  - !ruby/object:Gem::Version
268
+ hash: 3
269
+ segments:
270
+ - 0
218
271
  version: "0"
219
272
  requirements: []
220
273