http_router 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -215,6 +215,15 @@ class HttpRouter
215
215
  supported_methods.empty? ? @default_app.call(env) : [405, {'Allow' => supported_methods.sort.join(", ")}, []]
216
216
  end
217
217
 
218
+ def to_s
219
+ "#<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(', ')})>"
220
+ end
221
+
222
+ def inspect
223
+ head = to_s
224
+ "#{to_s}\n#{'=' * head.size}\n#{@root.inspect}"
225
+ end
226
+
218
227
  private
219
228
  def add_with_request_method(path, method, opts = {}, &app)
220
229
  route = add(path, opts).send(method.to_sym)
@@ -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)
@@ -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)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  class HttpRouter #:nodoc
3
- VERSION = '0.10.0'
3
+ VERSION = '0.10.1'
4
4
  end
@@ -86,4 +86,14 @@ class TestMisc < MiniTest::Unit::TestCase
86
86
  assert methods.include?(:rewrite_partial_path_info)
87
87
  assert methods.include?(:rewrite_path_info)
88
88
  end
89
+
90
+ def test_to_s_and_inspect
91
+ router = HttpRouter.new
92
+ router.add('/').to(:test)
93
+ router.add('/test').to(:test2)
94
+ router.post('/test').to(:test3)
95
+ 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\)>$/)
96
+ assert router.inspect.match(/^#<HttpRouter:0x[0-9a-f]+ number of routes \(3\) ignore_trailing_slash\? \(true\) redirect_trailing_slash\? \(false\) known_methods \(POST\)>/)
97
+ assert router.inspect.match(/Path: "\/test" for route unnamed route to :test3/)
98
+ end
89
99
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_router
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 10
9
- - 0
10
- version: 0.10.0
9
+ - 1
10
+ version: 0.10.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hull
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-01 00:00:00 -07:00
18
+ date: 2011-08-03 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency