scorched 0.18 → 0.19

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: cc448b9aca2411bb1687c2981fb9ba8d9f75429c
4
- data.tar.gz: 66c20180446fd507f019c645d87cad07b2098f1c
3
+ metadata.gz: 126d0553639f9a33afab401c7084a573a28914c4
4
+ data.tar.gz: ca8aaba8a210a5b48ec91be131ec9d5432be489a
5
5
  SHA512:
6
- metadata.gz: 2f48eea992d507bd058115c412b37c3c7e86697fad098d9be60872d983307e868cf0fd55d0f74b0d564c6c7c6fa22f745fa715e1382cbd966b5a208fa1ce6421
7
- data.tar.gz: 3cb2c849244e1a3316689d62575e524d5a2aa77aa77a7109bad7f836777187dfd544d30f475e562fb5bfc5018543dc2b1b1280ca3b06833d17e51dd668e8751c
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 `mapping` 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.
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 zero or more characters, excluding the forward slash.
61
- * `**` - Matches zero or more characters, including the forward slash.
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
@@ -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 controller if the parent class is
147
- # (or inherits from) a Scorched::Controller.
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
- regex_pattern = pattern.split(%r{(\*{1,2}|(?<!\\):{1,2}[^/*$]+)}).each_slice(2).map { |unmatched, match|
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]}>.*)" : "(?<#{match[1..-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
- regex_pattern << '$' if match_to_end
226
- Regexp.new(regex_pattern)
226
+ compiled_pattern << '$' if match_to_end
227
+ Regexp.new(compiled_pattern)
227
228
  end
228
229
  end
229
230
 
@@ -1,3 +1,3 @@
1
1
  module Scorched
2
- VERSION = '0.18'
2
+ VERSION = '0.19'
3
3
  end
@@ -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 zero or more characters" do
125
+ example "wildcards match one or more characters" do
126
126
  app << {pattern: '/*', target: proc { |env| [200, {}, ['ok']] }}
127
- rt.get('/').status.should == 200
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 == 200
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 == 200
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.18'
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-10-04 00:00:00.000000000 Z
11
+ date: 2013-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack