scorched 0.18 → 0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +3 -0
- data/Rakefile +1 -1
- data/docs/02_fundamentals/03_routing.md +4 -3
- data/lib/scorched/controller.rb +8 -7
- data/lib/scorched/version.rb +1 -1
- data/spec/controller_spec.rb +22 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 126d0553639f9a33afab401c7084a573a28914c4
|
4
|
+
data.tar.gz: ca8aaba8a210a5b48ec91be131ec9d5432be489a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: def1aa2f26ef50000e5a6689a4eeb9f120119968c6604915618d12f3d22211dbdf3e4ba080f4d79525c98848e8729b4b022a843bcab159fb870899efed7511db
|
7
|
+
data.tar.gz: 35cb01c416ccb4ed8e328476b5a7a1a80b76570e5d0229b9c02e7082f4eb078fdc92e868adcfaf227546761f8827a6d8b658cf970be30ed1dda2ef8608c0d81a
|
data/CHANGES.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
+
### v0.19
|
5
|
+
* The behaviour of wildcards '*' and '**' (and their _named_ equivalents) have been reverted to their original behviour of matching one or more characters, instead of zero or more. This means `/*` will no longer match `/`. Adding a question mark directly after a wildcard will have that wildcard match zero or more character, instead of one or more. So the pattern `/*?` will match both `/` and `/about`.
|
6
|
+
|
4
7
|
### v0.18
|
5
8
|
* Redirects now use a 303 or 302 HTTP status code by default, depending on HTTP version (similar logic to Sinatra). Trailing slash redirects (triggered by :strip_trailing_slash) still uses a 307 status.
|
6
9
|
|
data/Rakefile
CHANGED
@@ -26,7 +26,7 @@ desc 'Displays a pre-release message, requiring user input'
|
|
26
26
|
task :prerelease do
|
27
27
|
puts <<-MSG
|
28
28
|
|
29
|
-
About to release Scorched v#{Scorched::VERSION}. Please ensure CHANGES log is up-to-date, all relevant documentation is updated, and that any new files not under version control have been added/staged. Press any key to continue...
|
29
|
+
About to release Scorched v#{Scorched::VERSION}. Please ensure CHANGES log is up-to-date, all relevant documentation is updated, changes on Github master repository have been pulled and merged, and that any new files not under version control have been added/staged. Press any key to continue...
|
30
30
|
MSG
|
31
31
|
STDIN.gets
|
32
32
|
end
|
@@ -13,7 +13,7 @@ map pattern: '/', priority: -99, conditions: {method: ['POST', 'PUT', 'DELETE']}
|
|
13
13
|
|
14
14
|
The position the new mapping is inserted into the mapping hash is determined by it's priority, and the priority of the mappings already defined. This avoids re-sorting the mapping hash every time it's added to. This isn't a performance consideration, but is required to maintain the natural insert order of the mappings which have identical priorities (such as the default 0).
|
15
15
|
|
16
|
-
A `
|
16
|
+
A `mappings` method is also provided as means to access all defined mappings on a controller, but it should be considered read-only for the reasons just stated.
|
17
17
|
|
18
18
|
Route Helpers
|
19
19
|
-------------
|
@@ -57,10 +57,11 @@ Patterns can be defined as either a String or Regexp.
|
|
57
57
|
###String Patterns
|
58
58
|
String patterns are compiled into Regexp patterns corresponding to the following rules:
|
59
59
|
|
60
|
-
* `*` - Matches
|
61
|
-
* `**` - Matches
|
60
|
+
* `*` - Matches one or more characters, excluding the forward slash.
|
61
|
+
* `**` - Matches one or more characters, including the forward slash.
|
62
62
|
* `:param` - Same as `*` except the capture is named to whatever the string following the single-colon.
|
63
63
|
* `::param` - Same as `**` except the capture is named to whatever the string following the double-colon.
|
64
|
+
* `?` - If placed directly after a wildcard capture, matches zero or more characters instead of one or more. For example, the patterns `/*?` and `/::title?` would match both `/` and `/about`.
|
64
65
|
* `$` - If placed at the end of a pattern, the pattern only matches if it matches the entire path. For patterns defined using the route helpers, e.g. `Controller.route`, `Controller.get`, this is implied.
|
65
66
|
|
66
67
|
###Regex Patterns
|
data/lib/scorched/controller.rb
CHANGED
@@ -143,8 +143,8 @@ module Scorched
|
|
143
143
|
# inherits from, a mapping hash for setting conditions and so on, and of course a block which defines the
|
144
144
|
# controller class.
|
145
145
|
#
|
146
|
-
# It's worth noting, however obvious, that the resulting class will only be a
|
147
|
-
#
|
146
|
+
# It's worth noting, however obvious, that the resulting class will only be a Scorched::Controller if the parent
|
147
|
+
# class is, or inherits from, a Scorched::Controller.
|
148
148
|
def controller(pattern = '/', parent_class = self, **mapping, &block)
|
149
149
|
c = Class.new(parent_class, &block)
|
150
150
|
c.config[:auto_pass] = true if parent_class < Scorched::Controller
|
@@ -211,19 +211,20 @@ module Scorched
|
|
211
211
|
return pattern if Regexp === pattern
|
212
212
|
raise Error, "Can't compile URL of type #{pattern.class}. Must be String or Regexp." unless String === pattern
|
213
213
|
match_to_end = !!pattern.sub!(/\$$/, '') || match_to_end
|
214
|
-
|
214
|
+
compiled_pattern = pattern.split(%r{(\*{1,2}\??|(?<!\\):{1,2}[^/*$]+\??)}).each_slice(2).map { |unmatched, match|
|
215
215
|
Regexp.escape(unmatched) << begin
|
216
|
+
op = (match && match[-1] == '?' && match.chomp!('?')) ? '*' : '+'
|
216
217
|
if %w{* **}.include? match
|
217
|
-
match == '*' ? "([^/]
|
218
|
+
match == '*' ? "([^/]#{op})" : "(.#{op})"
|
218
219
|
elsif match
|
219
|
-
match[0..1] == '::' ? "(?<#{match[2..-1]}
|
220
|
+
match[0..1] == '::' ? "(?<#{match[2..-1]}>.#{op})" : "(?<#{match[1..-1]}>[^/]#{op})"
|
220
221
|
else
|
221
222
|
''
|
222
223
|
end
|
223
224
|
end
|
224
225
|
}.join
|
225
|
-
|
226
|
-
Regexp.new(
|
226
|
+
compiled_pattern << '$' if match_to_end
|
227
|
+
Regexp.new(compiled_pattern)
|
227
228
|
end
|
228
229
|
end
|
229
230
|
|
data/lib/scorched/version.rb
CHANGED
data/spec/controller_spec.rb
CHANGED
@@ -122,20 +122,38 @@ module Scorched
|
|
122
122
|
req.captures.should == {name: 'jeff', infliction: 'has/crabs'}
|
123
123
|
end
|
124
124
|
|
125
|
-
example "wildcards match
|
125
|
+
example "wildcards match one or more characters" do
|
126
126
|
app << {pattern: '/*', target: proc { |env| [200, {}, ['ok']] }}
|
127
|
-
rt.get('/').status.should ==
|
127
|
+
rt.get('/').status.should == 404
|
128
128
|
rt.get('/dog').status.should == 200
|
129
129
|
app.mappings.clear
|
130
130
|
app << {pattern: '/**', target: proc { |env| [200, {}, ['ok']] }}
|
131
|
-
rt.get('/').status.should ==
|
131
|
+
rt.get('/').status.should == 404
|
132
132
|
rt.get('/dog/cat').status.should == 200
|
133
133
|
app.mappings.clear
|
134
134
|
app << {pattern: '/:page', target: proc { |env| [200, {}, ['ok']] }}
|
135
|
-
rt.get('/').status.should ==
|
135
|
+
rt.get('/').status.should == 404
|
136
136
|
rt.get('/dog').status.should == 200
|
137
137
|
app.mappings.clear
|
138
138
|
app << {pattern: '/::page', target: proc { |env| [200, {}, ['ok']] }}
|
139
|
+
rt.get('/').status.should == 404
|
140
|
+
rt.get('/dog/cat').status.should == 200
|
141
|
+
end
|
142
|
+
|
143
|
+
example "wildcards can optionally match zero or more characters" do
|
144
|
+
app << {pattern: '/*?', target: proc { |env| [200, {}, ['ok']] }}
|
145
|
+
rt.get('/').status.should == 200
|
146
|
+
rt.get('/dog').status.should == 200
|
147
|
+
app.mappings.clear
|
148
|
+
app << {pattern: '/**?', target: proc { |env| [200, {}, ['ok']] }}
|
149
|
+
rt.get('/').status.should == 200
|
150
|
+
rt.get('/dog/cat').status.should == 200
|
151
|
+
app.mappings.clear
|
152
|
+
app << {pattern: '/:page?', target: proc { |env| [200, {}, ['ok']] }}
|
153
|
+
rt.get('/').status.should == 200
|
154
|
+
rt.get('/dog').status.should == 200
|
155
|
+
app.mappings.clear
|
156
|
+
app << {pattern: '/::page?', target: proc { |env| [200, {}, ['ok']] }}
|
139
157
|
rt.get('/').status.should == 200
|
140
158
|
rt.get('/dog/cat').status.should == 200
|
141
159
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scorched
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.19'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Wardrop
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|