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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c41ace391d4524a5b3214938ca0c03f2b2d335a9
4
- data.tar.gz: 8714cc1d1cd6a51d18fc6f7dd3ce4aa82bae86bc
3
+ metadata.gz: be0c4e4874218b5385f46e35c294adee75b85ace
4
+ data.tar.gz: 79c1bf0c6b92d21cf4a5059586ae8a9348281654
5
5
  SHA512:
6
- metadata.gz: 7790eaccb7bac3d7e643fb87d7e807755fcbb6a7e7d25d95b1de5b84385ab0a1ef9312ea8b71a682b46d3710745cc1c5c54bd7c7ccfe2b89c6a4006e3dab8e9c
7
- data.tar.gz: 04bc52e0687ec19021fdc3558ae3f59d6a0efd469465127604c5ea28c7d966746445e09060368a638fe52810eb2bc21dad4c51738e54526367f5fae9f1ade5a7
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)", ActionServlet, :defaults => { :format => "json" }
81
- s.match "/photos/:id(.:format)", ActionServlet, :format => "json"
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)
@@ -1,5 +1,5 @@
1
1
  module WEBrick
2
2
  module RouteServlet
3
- VERSION = "1.2.5"
3
+ VERSION = "1.2.6"
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.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshida Tetsuya