webrick-route_servlet 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/example/simple_action_servlet.rb +4 -0
- data/lib/webrick/route_servlet.rb +50 -13
- 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: 1a1b0f4ab6a7f0d6c068df163c11cd01434e9511
|
4
|
+
data.tar.gz: dd6622a22e81c2a4d99c99519af1e080491e6e3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb231b422ae59a9f130f6795d0868f0258c63bbcbed6660100f66acbd24e22e7a7264834db5b8e7637027a88a8a78fff60b64346bec8569723d735760170ea64
|
7
|
+
data.tar.gz: 7c225b2f52c7aac4d728091a87348c392d1066bf50f30d52b22a56db91badb9439183b084cfc2ceb3402b200d5ae3d28a4062ef993838ca9c1af36dd8a21dcf5
|
@@ -88,6 +88,10 @@ class NotFoundServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
88
88
|
res.body += "path: #{req.params[:path]}"
|
89
89
|
res.body += "<p><a href='/'>index</a></p>"
|
90
90
|
end
|
91
|
+
|
92
|
+
def do_POST(req, res)
|
93
|
+
do_GET(req, res)
|
94
|
+
end
|
91
95
|
end
|
92
96
|
|
93
97
|
server = WEBrick::HTTPServer.new(:Port=>3000)
|
@@ -79,23 +79,39 @@ module WEBrick
|
|
79
79
|
|
80
80
|
def resources(re, servlet, *servlet_options, **request_options)
|
81
81
|
re = re.to_s.sub(%r#/$#, "")
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
82
|
+
|
83
|
+
actions = {
|
84
|
+
:index => [:get, "#{re}(.:format)"],
|
85
|
+
:create => [:post, "#{re}(.:format)"],
|
86
|
+
:new => [:get, "#{re}/new(.:format)"],
|
87
|
+
:edit => [:get, "#{re}/:id/edit(.:format)"],
|
88
|
+
:show => [:get, "#{re}/:id(.:format)"],
|
89
|
+
:update => [:put, "#{re}/:id(.:format)"],
|
90
|
+
:delete => [:delete, "#{re}/:id(.:format)"],
|
91
|
+
}
|
92
|
+
actions = _select_rest_actions(actions, request_options)
|
93
|
+
|
94
|
+
actions.each do |action, (method, re)|
|
95
|
+
send(method, re, servlet, *servlet_options, request_options.merge({:action => action}))
|
96
|
+
end
|
89
97
|
end
|
90
98
|
|
91
99
|
def resource(re, servlet, *servlet_options, **request_options)
|
92
100
|
re = re.to_s.sub(%r#/$#, "")
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
101
|
+
|
102
|
+
actions = {
|
103
|
+
:create => [:post, "#{re}(.:format)"],
|
104
|
+
:new => [:get, "#{re}/new(.:format)"],
|
105
|
+
:edit => [:get, "#{re}/edit(.:format)"],
|
106
|
+
:show => [:get, "#{re}(.:format)"],
|
107
|
+
:update => [:put, "#{re}(.:format)"],
|
108
|
+
:delete => [:delete, "#{re}(.:format)"],
|
109
|
+
}
|
110
|
+
actions = _select_rest_actions(actions, request_options)
|
111
|
+
|
112
|
+
actions.each do |action, (method, re)|
|
113
|
+
send(method, re, servlet, *servlet_options, request_options.merge({:action => action}))
|
114
|
+
end
|
99
115
|
end
|
100
116
|
|
101
117
|
def routes
|
@@ -121,6 +137,27 @@ module WEBrick
|
|
121
137
|
re
|
122
138
|
end
|
123
139
|
private :_normalize_path_re
|
140
|
+
|
141
|
+
def _select_rest_actions(actions, request_options)
|
142
|
+
actions
|
143
|
+
|
144
|
+
# only
|
145
|
+
if request_options[:only]
|
146
|
+
only = request_options[:only]
|
147
|
+
only = [only] unless Array===only
|
148
|
+
actions.select!{|k,v| only.include?(k)}
|
149
|
+
end
|
150
|
+
|
151
|
+
# expect
|
152
|
+
if request_options[:expect]
|
153
|
+
expect = request_options[:expect]
|
154
|
+
expect = [expect] unless Array===expect
|
155
|
+
actions.delete_if{|k,v| expect.include?(k)}
|
156
|
+
end
|
157
|
+
|
158
|
+
actions
|
159
|
+
end
|
160
|
+
private :_select_rest_actions
|
124
161
|
end
|
125
162
|
|
126
163
|
class << self
|