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.
- data/lib/http_router.rb +9 -0
- data/lib/http_router/node.rb +21 -0
- data/lib/http_router/node/lookup.rb +10 -0
- data/lib/http_router/node/path.rb +4 -0
- data/lib/http_router/node/request.rb +4 -0
- data/lib/http_router/node/root.rb +8 -0
- data/lib/http_router/version.rb +1 -1
- data/test/test_misc.rb +10 -0
- metadata +4 -4
data/lib/http_router.rb
CHANGED
@@ -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)
|
data/lib/http_router/node.rb
CHANGED
@@ -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} "
|
data/lib/http_router/version.rb
CHANGED
data/test/test_misc.rb
CHANGED
@@ -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:
|
4
|
+
hash: 53
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 10
|
9
|
-
-
|
10
|
-
version: 0.10.
|
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-
|
18
|
+
date: 2011-08-03 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|