http_router 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/http_router/node/request.rb +22 -1
- data/lib/http_router/node.rb +23 -9
- data/lib/http_router/version.rb +1 -1
- metadata +4 -4
@@ -2,15 +2,36 @@ class HttpRouter
|
|
2
2
|
class Node
|
3
3
|
class Request < Node
|
4
4
|
def self.request_methods
|
5
|
-
[:host, :
|
5
|
+
[:host, :scheme, :request_method, :user_agent]
|
6
6
|
end
|
7
7
|
|
8
|
+
attr_reader :request_method
|
9
|
+
|
8
10
|
def initialize(router)
|
9
11
|
@router, @linear, @catchall, @lookup = router, [], nil, {}
|
10
12
|
end
|
11
13
|
|
14
|
+
def transform_to(meth)
|
15
|
+
new_node = Request.new(router)
|
16
|
+
new_node.request_method = @request_method
|
17
|
+
new_node.instance_var_set(:@linear, @linear.dup)
|
18
|
+
new_node.instance_var_set(:@catchall, @catchall)
|
19
|
+
new_node.instance_var_set(:@lookup, @lookup.dup)
|
20
|
+
@linear.clear
|
21
|
+
@lookup.clear
|
22
|
+
@catchall = new_node
|
23
|
+
@request_method = meth
|
24
|
+
new_node
|
25
|
+
end
|
26
|
+
|
12
27
|
def request_method=(meth)
|
13
28
|
@request_method = meth == :method ? :request_method : meth
|
29
|
+
if @destination
|
30
|
+
next_node = add_catchall
|
31
|
+
next_node.instance_variable_set(:@destination, (next_node.instance_variable_get(:@destination) || []).concat(@destination))
|
32
|
+
@destination.clear
|
33
|
+
end
|
34
|
+
@request_method
|
14
35
|
end
|
15
36
|
|
16
37
|
def add_lookup(val)
|
data/lib/http_router/node.rb
CHANGED
@@ -95,16 +95,30 @@ class HttpRouter
|
|
95
95
|
@request ||= Request.new(@router)
|
96
96
|
next_requests = [@request]
|
97
97
|
Request.request_methods.each do |method|
|
98
|
+
method_index = Request.request_methods.index(method)
|
98
99
|
next_requests.map! do |next_request|
|
99
|
-
next_request.request_method
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
100
|
+
if opts[method].nil? && next_request.request_method.nil?
|
101
|
+
next_request
|
102
|
+
else
|
103
|
+
next_request_index = next_request.request_method && Request.request_methods.index(next_request.request_method)
|
104
|
+
rank = next_request_index ? method_index <=> next_request_index : 0
|
105
|
+
case rank
|
106
|
+
when 0
|
107
|
+
next_request.request_method = method
|
108
|
+
(opts[method].nil? ? [nil] : Array(opts[method])).map do |request_matcher|
|
109
|
+
case request_matcher
|
110
|
+
when nil
|
111
|
+
next_request.add_catchall
|
112
|
+
when String
|
113
|
+
next_request.add_lookup(request_matcher)
|
114
|
+
when Regexp
|
115
|
+
next_request.add_linear(request_matcher)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
when -1
|
119
|
+
next_request
|
120
|
+
when 1
|
121
|
+
next_request.transform_to(method)
|
108
122
|
end
|
109
123
|
end
|
110
124
|
end
|
data/lib/http_router/version.rb
CHANGED
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: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 1
|
10
|
+
version: 0.6.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-03-
|
18
|
+
date: 2011-03-20 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|