webrick-route_servlet 1.2.5 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/lib/webrick/route_servlet.rb +9 -1
- data/lib/webrick/route_servlet/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be0c4e4874218b5385f46e35c294adee75b85ace
|
4
|
+
data.tar.gz: 79c1bf0c6b92d21cf4a5059586ae8a9348281654
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca91db9a0dde9ad0415d5558e837ed1ac5fea3ec4d366480a08db82ac8328938ee66870745cf4b38ea670ef7f27aea3abadd055468680a586ce65cb2b04d0e73
|
7
|
+
data.tar.gz: 64b0bcdf8a7b0d0f257065fd54cc70ffe8d01e0cc28063fd848eb01c5c9d3d4633e1b7248b0cf154ab5f4da186599a4855c252a1e7caf73e782d275695ef069e
|
data/README.md
CHANGED
@@ -69,6 +69,13 @@ constraints
|
|
69
69
|
|
70
70
|
s.match "/photos/:id", PhotoServlet, :constraints => { :id => /[A-Z]\d{5}/ }
|
71
71
|
s.match "/photos/:id", PhotoServlet, :id => /[A-Z]\d{5}/
|
72
|
+
s.match "/photos/:id", PhotoServlet, :constraints => PhotoConstraint.new
|
73
|
+
|
74
|
+
class PhotoConstraint
|
75
|
+
def matches?(req)
|
76
|
+
/[A-Z]\d{5}/===req.params[:id]
|
77
|
+
end
|
78
|
+
end
|
72
79
|
|
73
80
|
only / except
|
74
81
|
|
@@ -77,8 +84,8 @@ only / except
|
|
77
84
|
|
78
85
|
defaults
|
79
86
|
|
80
|
-
s.match "/photos/:id(.:format)",
|
81
|
-
s.match "/photos/:id(.:format)",
|
87
|
+
s.match "/photos/:id(.:format)", PhotoServlet, :defaults => { :format => "json" }
|
88
|
+
s.match "/photos/:id(.:format)", PhotoServlet, :format => "json"
|
82
89
|
|
83
90
|
## Contributing
|
84
91
|
|
@@ -56,8 +56,16 @@ module WEBrick
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
# set
|
59
60
|
req.action = params[:action] || request_options[:action]
|
60
61
|
req.params = params
|
62
|
+
|
63
|
+
# advanced constraints
|
64
|
+
constraints = request_options[:constraints]
|
65
|
+
if constraints.respond_to?(:matches?)
|
66
|
+
next unless constraints.matches?(req)
|
67
|
+
end
|
68
|
+
|
61
69
|
return [servlet, servlet_options]
|
62
70
|
end
|
63
71
|
end
|
@@ -146,7 +154,7 @@ module WEBrick
|
|
146
154
|
keys = re.scan(%r#:([^/()\.]+)#).map(&:first).sort{|a,b| b.length <=> a.length}
|
147
155
|
keys.each do |key|
|
148
156
|
value_re = Regexp.new("(?<#{key}>[^/]+?)")
|
149
|
-
if Regexp===constraints[key.to_sym]
|
157
|
+
if constraints.respond_to?(:[]) && Regexp===constraints[key.to_sym]
|
150
158
|
value_re = /(?<#{key}>#{constraints[key.to_sym]})/
|
151
159
|
end
|
152
160
|
re = re.gsub(":#{key}", value_re.to_s)
|