webrick-route_servlet 1.2.6 → 1.2.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be0c4e4874218b5385f46e35c294adee75b85ace
4
- data.tar.gz: 79c1bf0c6b92d21cf4a5059586ae8a9348281654
3
+ metadata.gz: 59db5b865d282727f1700c6b59f5bea65eb075fc
4
+ data.tar.gz: 965f884f6e5ecf9f824a924f93a35137872439ad
5
5
  SHA512:
6
- metadata.gz: ca91db9a0dde9ad0415d5558e837ed1ac5fea3ec4d366480a08db82ac8328938ee66870745cf4b38ea670ef7f27aea3abadd055468680a586ce65cb2b04d0e73
7
- data.tar.gz: 64b0bcdf8a7b0d0f257065fd54cc70ffe8d01e0cc28063fd848eb01c5c9d3d4633e1b7248b0cf154ab5f4da186599a4855c252a1e7caf73e782d275695ef069e
6
+ metadata.gz: 70b4ecbe5bddc1d6e2ea08aff9f83f82e30e3d1833366d42208105ece4140fe249dae40de6bed1da1224328dd85ef12b089eb0b4b0ffdc00355b63700e7e9d59
7
+ data.tar.gz: 65b60c7c7f21c2672d995ad96c12d36e245a590e9886b0ffd43962fde8b3081affaec5e71dde9e275e816adffa4e40ec1392961283c9efe6fc0bc5f8f7a4aa55
data/README.md CHANGED
@@ -77,9 +77,14 @@ constraints
77
77
  end
78
78
  end
79
79
 
80
- only / except
80
+ only
81
81
 
82
- s.resources "/photo", PhotoServlet, :only => [:index]
82
+ s.resources "/photo", PhotoServlet, :only => :index
83
+ s.resources "/photo", PhotoServlet, :only => [:index, :show]
84
+
85
+ except
86
+
87
+ s.resources "/photo", PhotoServlet, :except => :index
83
88
  s.resources "/photo", PhotoServlet, :except => [:index, :show]
84
89
 
85
90
  defaults
@@ -15,17 +15,18 @@ class IndexServlet < WEBrick::HTTPServlet::AbstractServlet
15
15
  res.body += create_link("GET", "/users/new", "new")
16
16
  res.body += create_link("GET", "/users/1/edit", "edit")
17
17
  res.body += create_link("GET", "/users/1", "show")
18
- res.body += create_link("PUT", "/users/1", "update", true)
19
- res.body += create_link("DELETE", "/users/1", "destroy", true)
18
+ res.body += create_link("PUT", "/users/1", "update")
19
+ res.body += create_link("DELETE", "/users/1", "destroy")
20
20
  res.body += "<br />"
21
21
  res.body += "<h4>NotFoundServlet:</h4>"
22
22
  res.body += "<a href='/no/match/path/route'>/no/match/path/route</a><br />"
23
23
  end
24
24
 
25
- def create_link(method, path, action, disabled=false)
26
- disabled = disabled ? " disabled='disabled'" : ""
27
- "<form action='#{path}' method='#{method}'>\n" +
28
- "<input type='submit' value='#{method} #{path} => #{action}'#{disabled} />\n" +
25
+ def create_link(method, path, action)
26
+ method2 = method=="GET" ? "GET" : "POST"
27
+ "<form action='#{path}' method='#{method2}'>\n" +
28
+ "<input type='hidden' name='_method' value='#{method}' />\n" +
29
+ "<input type='submit' value='#{method} #{path} => #{action}' />\n" +
29
30
  "</form>\n"
30
31
  end
31
32
  end
@@ -41,8 +41,13 @@ module WEBrick
41
41
  end
42
42
 
43
43
  def select_route(req)
44
+ req_method = req.request_method.to_sym
45
+ if req.query["_method"]
46
+ req_method = req.query["_method"].upcase.to_sym
47
+ end
48
+
44
49
  self.class.routes.each do |method, re, servlet, servlet_options, request_options|
45
- if method==:* || method==req.request_method.to_sym
50
+ if method==:* || method==req_method
46
51
  md = re.match(req.path_info)
47
52
  if md
48
53
  # path params
@@ -108,7 +113,7 @@ module WEBrick
108
113
  :edit => [:get, "#{re}/:id/edit(.:format)"],
109
114
  :show => [:get, "#{re}/:id(.:format)"],
110
115
  :update => [:put, "#{re}/:id(.:format)"],
111
- :delete => [:delete, "#{re}/:id(.:format)"],
116
+ :destroy => [:delete, "#{re}/:id(.:format)"],
112
117
  }
113
118
  _select_rest_actions(actions, request_options)
114
119
 
@@ -121,12 +126,12 @@ module WEBrick
121
126
  re = re.to_s.sub(%r#/$#, "")
122
127
 
123
128
  actions = {
124
- :create => [:post, "#{re}(.:format)"],
125
- :new => [:get, "#{re}/new(.:format)"],
126
- :edit => [:get, "#{re}/edit(.:format)"],
127
- :show => [:get, "#{re}(.:format)"],
128
- :update => [:put, "#{re}(.:format)"],
129
- :delete => [:delete, "#{re}(.:format)"],
129
+ :create => [:post, "#{re}(.:format)"],
130
+ :new => [:get, "#{re}/new(.:format)"],
131
+ :edit => [:get, "#{re}/edit(.:format)"],
132
+ :show => [:get, "#{re}(.:format)"],
133
+ :update => [:put, "#{re}(.:format)"],
134
+ :destroy => [:delete, "#{re}(.:format)"],
130
135
  }
131
136
  _select_rest_actions(actions, request_options)
132
137
 
@@ -1,5 +1,5 @@
1
1
  module WEBrick
2
2
  module RouteServlet
3
- VERSION = "1.2.6"
3
+ VERSION = "1.2.7"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webrick-route_servlet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshida Tetsuya