scorched 0.10 → 0.11

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: 08889289c8e64bbfd860c495a1e0319c5c1c9310
4
- data.tar.gz: 7c203bcdc50f2070e157302e6daa8b442c8a6694
3
+ metadata.gz: d5471fecce817d61997c06ba5a8b8837192ac675
4
+ data.tar.gz: ae192c4683cc8a68820b106932e79b4497320659
5
5
  SHA512:
6
- metadata.gz: 5aaa29d4c05e8bc4b4a2e11381c6a6030f91cbe0e3d2d7d312eabceabcae3447d742485852bfc115938526e21d32fa1399777737eaae9e71a40fe1f2879e8f11
7
- data.tar.gz: 17c71a09fb5cf953a3dd96b880be3d68332622002ca3dfe9c1393b72e3141c63ea1fb4009bb0044f18a923c6f5e95657781a4514e50745f2735895f830fff57f
6
+ metadata.gz: 1a53207a5993f65218855fcfb7501c45d0fc0924c3151bfadba17d36bd7b18fa02ece678f30e5c2842db29f88a8818b9b09f8128f971291c6258de1cf40a1480
7
+ data.tar.gz: 023d34b537a6b1626800abb434be8672d8e08132ebb5c527d59716b6b1306fda6fea7771e2a279652ce165418dbb7d7dd9436deb2ceedb03ac035adff3a974b0
data/Gemfile CHANGED
File without changes
data/LICENSE CHANGED
File without changes
@@ -3,6 +3,11 @@ Milestones
3
3
 
4
4
  Changelog
5
5
  ---------
6
+ ### v0.11
7
+ * Route wildcards '*' and '**' (and their named equivalents) now match zero or more characters, instead of one or more. This means `/*` will now match both `/` and `/about` for example.
8
+ * Conditions can now be inverted by appending an exclamation mark to the condition, e.g. `method!: 'GET'` matches all HTTP methods, excluding GET.
9
+ * While not strictly Scorched related, one planned feature for Scorched was to implement a simple form population mechanism. This has instead been implemented as a stand-alone project, [Formless](https://github.com/Wardrop/Formless), which can be used with any framework or application, including Scorched.
10
+
6
11
  ### v0.10
7
12
  * Route matching internals have been refactored.
8
13
  * Match information is now stored in the `Match` struct for better formalisation.
@@ -92,12 +97,6 @@ Some of these remaining features may be reconsidered and either left out, or put
92
97
 
93
98
  * If one or more matches are found, but their conditions don't pass, a 403 should be returned instead of a 404.
94
99
  * Make specs for Collection and Options classes more thorough, e.g. test all non-reading modifiers such as clear, delete, etc.
95
- * Add more view helpers, maybe?
96
- * Add helper to easily read and build HTTP query strings. Takes care of "?" and "&" logic, escaping, etc. This is
97
- intended to make link building easier.
98
- * Form populator implemented with Nokogiri. This would have to be added to a contrib library.
99
- * Add Verbose logging, including debug logging to show each routing hop and the current environment (variables, mode, etc)
100
- * I need feedback on what order _after_ filters should be run. While it's somewhat intuitive for them to run in the order they're defined, it could also be considered intuitive for the first defined _after_ filter to be the last to touch the outgoing response; to have priority.
101
100
 
102
101
 
103
102
  Unlikely
@@ -107,6 +106,7 @@ These features are unlikely to be implemented unless someone provides a good rea
107
106
  * Mutex locking option - I'm of the opinion that the web server should be configured for the concurrency model of the application, rather than the framework.
108
107
  * Using Rack::Protection by default - The problem here is that a good portion of Rack::Protection involves sessions, and given that Scorched doesn't itself load any session middleware, these components of Rack::Protection would have to be excluded. I wouldn't want to invoke a false sense of security
109
108
  * Filter priorities - They're technically possible, but I believe it would introduce the potential for _filter hell_; badly written filters and mass confusion. Filter order has to be logical and predictable. Adding prioritisation would undermine that, and make for lazy use of filters. By not having prioritisation, there's incentive to design filters to be order-agnostic.
109
+ * Verbose logging - I originally intended to add some form of debug-style logging to show the complete flow of a request as it traverses through filters and controllers, etc. For a couple of reasons, I've decided to leave this out of Scorched. For those unfamiliar with the order in which filters and routes are invoked, it's better to learn through first-hand experience writing little test applications, rather than depending on debug logging.
110
110
 
111
111
 
112
112
  More things will be added as they're thought of and considered.
@@ -191,9 +191,9 @@ module Scorched
191
191
  regex_pattern = pattern.split(%r{(\*{1,2}|(?<!\\):{1,2}[^/*$]+)}).each_slice(2).map { |unmatched, match|
192
192
  Regexp.escape(unmatched) << begin
193
193
  if %w{* **}.include? match
194
- match == '*' ? "([^/]+)" : "(.+)"
194
+ match == '*' ? "([^/]*)" : "(.*)"
195
195
  elsif match
196
- match[0..1] == '::' ? "(?<#{match[2..-1]}>.+)" : "(?<#{match[1..-1]}>[^/]+)"
196
+ match[0..1] == '::' ? "(?<#{match[2..-1]}>.*)" : "(?<#{match[1..-1]}>[^/]*)"
197
197
  else
198
198
  ''
199
199
  end
@@ -288,13 +288,19 @@ module Scorched
288
288
 
289
289
  # Tests the given conditions, returning the name of the first failed condition, or nil otherwise.
290
290
  def check_for_failed_condition(conds)
291
- (conds || []).find { |c,v| check_condition?(c, v) ? false : c }
291
+ failed = (conds || []).find { |c, v| !check_condition?(c, v) }
292
+ if failed
293
+ failed[0] = failed[0][0..-2].to_sym if failed[0][-1] == '!'
294
+ end
295
+ failed
292
296
  end
293
297
 
294
298
  # Test the given condition, returning true if the condition passes, or false otherwise.
295
299
  def check_condition?(c, v)
300
+ c = c[0..-2].to_sym if invert = (c[-1] == '!')
296
301
  raise Error, "The condition `#{c}` either does not exist, or is not an instance of Proc" unless Proc === self.conditions[c]
297
- instance_exec(v, &self.conditions[c])
302
+ retval = instance_exec(v, &self.conditions[c])
303
+ invert ? !retval : !!retval
298
304
  end
299
305
 
300
306
  def redirect(url, status = 307)
File without changes
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module Scorched
2
- VERSION = '0.10'
2
+ VERSION = '0.11'
3
3
  end
@@ -110,6 +110,24 @@ module Scorched
110
110
  req.captures.should == {name: 'jeff', infliction: 'has/crabs'}
111
111
  end
112
112
 
113
+ example "wildcards match zero or more characters" do
114
+ app << {pattern: '/*', target: proc { |env| [200, {}, ['ok']] }}
115
+ rt.get('/').status.should == 200
116
+ rt.get('/dog').status.should == 200
117
+ app.mappings.clear
118
+ app << {pattern: '/**', target: proc { |env| [200, {}, ['ok']] }}
119
+ rt.get('/').status.should == 200
120
+ rt.get('/dog/cat').status.should == 200
121
+ app.mappings.clear
122
+ app << {pattern: '/:page', target: proc { |env| [200, {}, ['ok']] }}
123
+ rt.get('/').status.should == 200
124
+ rt.get('/dog').status.should == 200
125
+ app.mappings.clear
126
+ app << {pattern: '/::page', target: proc { |env| [200, {}, ['ok']] }}
127
+ rt.get('/').status.should == 200
128
+ rt.get('/dog/cat').status.should == 200
129
+ end
130
+
113
131
  it "can match regex and preserve anonymous captures" do
114
132
  req = nil
115
133
  app << {pattern: %r{/anon/([^/]+)/(.+)}, target: proc do |env|
@@ -175,6 +193,12 @@ module Scorched
175
193
  rt.get("/").body.should == 'get'
176
194
  rt.post("/").body.should == 'post'
177
195
  end
196
+
197
+ it "inverts the conditions if it's referenced with a trailing exclamation mark" do
198
+ app << {pattern: '/', conditions: {method!: 'GET'}, target: proc { |env| [200, {}, ['ok']] }}
199
+ rt.get("/").status.should == 405
200
+ rt.post("/").status.should == 200
201
+ end
178
202
  end
179
203
 
180
204
  describe "route helpers" do
@@ -556,6 +580,34 @@ module Scorched
556
580
  end
557
581
  end
558
582
 
583
+ describe "status codes" do
584
+ it "returns 405 when :method condition fails" do
585
+ app.get('/') { }
586
+ rt.post('/').status.should == 405
587
+ end
588
+
589
+ it "returns 404 when :host condition fails" do
590
+ app.get('/', host: 'somehost') { }
591
+ rt.get('/').status.should == 404
592
+ end
593
+
594
+ it "returns 406 when accept-related conditions fail" do
595
+ app.get('/media_type', media_type: 'application/json') { }
596
+ app.get('/charset', charset: 'iso-8859-5') { }
597
+ app.get('/encoding', encoding: 'gzip') { }
598
+ app.get('/language', language: 'en') { }
599
+
600
+ rt.get('/media_type', {}, 'HTTP_ACCEPT' => 'application/json').status.should == 200
601
+ rt.get('/media_type', {}, 'HTTP_ACCEPT' => 'text/html').status.should == 406
602
+ rt.get('/charset', {}, 'HTTP_ACCEPT_CHARSET' => 'iso-8859-5').status.should == 200
603
+ rt.get('/charset', {}, 'HTTP_ACCEPT_CHARSET' => 'iso-8859-5;q=0').status.should == 406
604
+ rt.get('/encoding', {}, 'HTTP_ACCEPT_ENCODING' => 'gzip').status.should == 200
605
+ rt.get('/encoding', {}, 'HTTP_ACCEPT_ENCODING' => 'compress').status.should == 406
606
+ rt.get('/language', {}, 'HTTP_ACCEPT_LANGUAGE' => 'en').status.should == 200
607
+ rt.get('/language', {}, 'HTTP_ACCEPT_LANGUAGE' => 'da').status.should == 406
608
+ end
609
+ end
610
+
559
611
  describe "configuration" do
560
612
  describe :strip_trailing_slash do
561
613
  it "can be set to strip trailing slash and redirect" do
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
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.10'
4
+ version: '0.11'
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-03-31 00:00:00.000000000 Z
11
+ date: 2013-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -163,4 +163,3 @@ test_files:
163
163
  - spec/controller_spec.rb
164
164
  - spec/options_spec.rb
165
165
  - spec/request_spec.rb
166
- has_rdoc: