scorched 0.13 → 0.14

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: 097dc690273075ecec2044e7ef6cc9ef285e4c03
4
- data.tar.gz: ceac380dfda10425b551488c953e34efc4d681a6
3
+ metadata.gz: 2583f96bd04c7a31f7edf598acd84eaa11689feb
4
+ data.tar.gz: 8148c65523e21d3aaa68b6dd2dd7ce0ac62eddac
5
5
  SHA512:
6
- metadata.gz: 8b67fe3315887ef8cc9863c1353a803ff27e82d9f5c6ecb6b3d1b611077c1ec2ffad754e175e8adecaba2fb50f1ad7d96f3f3e5ce27f83c4005a5b5c44df8745
7
- data.tar.gz: 4d68ca06da03b5cf45d25191b6786008591066f85e2bceb246e82e6ffccbef6d21a357e2534ee5114855e81015712cf3de584cb2ba93145fa213dc80c926b779
6
+ metadata.gz: 73ed932ce8783845f70c041da390eca59f9bb487b834191a31863a2e8f23290457317db4a8fccf574aaaba3d17530d5e8cd36a739491af61bda024daaab75086
7
+ data.tar.gz: 8ac3bd00774d449e68e40d90639a937c5b7963c9630b5aa86a478b283b8eb6f5586188bc7cc5bc85d48c6b7c8630b1c22a43aad551ad6488e47ebf6b529abafc
data/CHANGES.md CHANGED
@@ -1,6 +1,10 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ### v0.14
5
+ * If a matched mapping _passes_ the request and there are no other matching mappings, a 404 status is now set by default, rather than a 200 status.
6
+ * Renamed `matched` condition to `handled` to be less ambiguous.
7
+
4
8
  ### v0.13
5
9
  * Added `content_type` condition, corresponding to the `Content-Type` request header.
6
10
  * Reverted rogue commit containing experimental debugging logging that I didn't plan to merge. Fixes issue #12.
@@ -0,0 +1,25 @@
1
+ require 'fileutils'
2
+ require 'rspec'
3
+ require 'rspec/core/rake_task'
4
+ require 'rake/clean'
5
+ require './lib/scorched/version'
6
+
7
+ CLEAN.include "pkg"
8
+
9
+ task :default => :spec
10
+ task :test => :spec
11
+
12
+ RSpec::Core::RakeTask.new(:spec)
13
+
14
+ task :release => [:spec, :'gem:install', :commit_version, :'gem:release', :clean]
15
+
16
+ task :commit_version do
17
+ sh "git commit --allow-empty -a -m 'v#{Scorched::VERSION} release.' &&
18
+ git tag -a #{Scorched::VERSION} -m 'v#{Scorched::VERSION} release.' &&
19
+ git push &&
20
+ git push --tags"
21
+ end
22
+
23
+ namespace :gem do
24
+ require "bundler/gem_tasks"
25
+ end
@@ -75,7 +75,7 @@ Conditions are essentially just pre-requisites that must be met before a mapping
75
75
  * `:host` - The host name (i.e. domain name) used in the request.
76
76
  * `:language` - Languages accepted by the client.
77
77
  * `:media_type` - Media types (i.e. content types) accepted by the client.
78
- * `:matched` - Whether a mapping in the controller instance was invoked as the target for the request.
78
+ * `:handled` - Whether a mapping in the controller instance was invoked as the target for the request. A mapping that _passes_ a request is not considered a match.
79
79
  * `:method` - The request method used, e.g. GET, POST, PUT, ... .
80
80
  * `:proc` - An on-the-fly condition to be evaluated in the context of the controller instance. Should return true if the condition was satisfied, or false otherwise.
81
81
  * `:user_agent` - The user agent string provided with the request. Takes a Regexp or String.
@@ -13,7 +13,7 @@ Scorched Extras
13
13
  ---------------
14
14
  As mentioned, Scorched tacks a few extras onto it's `Scorched::Request` and `Scorched::Response` classes. Most of these extras were added as a requirement of the Scorched controller, but they're just as useful to other developers.
15
15
 
16
- Refer to the generated API documentation for `Scorched::Request` and `Scorched::Response`.
16
+ Refer to the API documentation for `Scorched::Request` and `Scorched::Response`.
17
17
 
18
18
 
19
19
  Halting Requests
@@ -22,13 +22,15 @@ There may be instances we're you want to shortcut out-of processing the current
22
22
 
23
23
  When `halt` is called within a route, it simply exists out of that route, and begins processing any _after_ filters. Halt can also be used within a _before_ or _after_ filter, in which case any remaining filters in the current controller are skipped.
24
24
 
25
- Calls to `halt` don't propagate up the controller chain. They're local to the controller. A call to `halt` is equivalent to doing a `throw :halt`. Calling `halt` is often preferred though because as well as being shorter, it can take an optional argument to set the response status, which is something you typically want to do when halting a request.
25
+ Calls to `halt` don't propagate up the controller chain. They're local to the controller. A call to `halt` is equivalent to doing a manual `throw :halt`. Calling `halt` is often preferred though because as well as being syntactically sweeter, it can take an optional argument to set the response status and body, which is something you likely want to do when halting a request.
26
26
 
27
27
 
28
28
  Passing Requests
29
29
  ----------------
30
30
  A route may _pass_ a request to the next matching route. _passing_ is very similar to halting, except an opportunity is given to other matching routes to fulfil the request. This is implemented as a throw/catch mechanism, much the same as `halt`. You can do a `throw :pass` manually, or use the helper method `pass`.
31
31
 
32
+ If a target passes a request, the request is still considered _unmatched_ or _unsatisfied_. Hence, if no other target matches the passed request, a 404 is returned as the response status by default.
33
+
32
34
 
33
35
  Redirections
34
36
  ------------
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../../lib/scorched.rb', __FILE__)
2
+
3
+ class MyApp < Scorched::Controller
4
+ controller '/' do
5
+
6
+ end
7
+
8
+ after do
9
+ p @_matched
10
+ end
11
+ end
12
+
13
+ run MyApp
@@ -67,8 +67,8 @@ module Scorched
67
67
  method: proc { |methods|
68
68
  [*methods].include?(request.request_method)
69
69
  },
70
- matched: proc { |bool|
71
- @_matched == bool
70
+ handled: proc { |bool|
71
+ @_handled == bool
72
72
  },
73
73
  proc: proc { |*blocks|
74
74
  [*blocks].all? { |b| instance_exec(&b) }
@@ -256,23 +256,22 @@ module Scorched
256
256
  if config[:strip_trailing_slash] == :redirect && request.path =~ %r{./$}
257
257
  redirect(request.path.chomp('/'))
258
258
  end
259
-
260
- if matches.all? { |m| m.failed_condition }
261
- pass if config[:auto_pass]
262
- response.status = matches.empty? ? 404 : 403
263
- end
264
-
259
+ eligable_matches = matches.reject { |m| m.failed_condition }
260
+ pass if config[:auto_pass] && eligable_matches.empty?
265
261
  run_filters(:before)
266
262
  begin
267
- @_matched = true == matches.each { |match|
268
- next if match.failed_condition
263
+ eligable_matches.each { |match|
269
264
  request.breadcrumb << match
270
265
  break if catch(:pass) {
271
266
  target = match.mapping[:target]
272
267
  response.merge! (Proc === target) ? instance_exec(env, &target) : target.call(env)
268
+ @_handled = true
273
269
  }
274
270
  request.breadcrumb.pop
275
271
  }
272
+ unless @_handled
273
+ response.status = (!matches.empty? && eligable_matches.empty?) ? 403 : 404
274
+ end
276
275
  rescue => inner_error
277
276
  rescue_block.call(inner_error)
278
277
  end
@@ -290,10 +289,10 @@ module Scorched
290
289
  # The `:eligable` attribute of the `Match` object indicates whether the conditions for that mapping passed.
291
290
  # The result is cached for the life time of the controller instance, for the sake of effecient-recalling.
292
291
  def matches
293
- return @matches if @matches
292
+ return @_matches if @_matches
294
293
  to_match = request.unmatched_path
295
294
  to_match = to_match.chomp('/') if config[:strip_trailing_slash] == :ignore && to_match =~ %r{./$}
296
- @matches = mappings.map { |mapping|
295
+ @_matches = mappings.map { |mapping|
297
296
  mapping[:pattern].match(to_match) do |match_data|
298
297
  if match_data.pre_match == ''
299
298
  if match_data.names.empty?
@@ -1,3 +1,3 @@
1
1
  module Scorched
2
- VERSION = '0.13'
2
+ VERSION = '0.14'
3
3
  end
@@ -19,4 +19,5 @@ Gem::Specification.new 'scorched', Scorched::VERSION do |s|
19
19
  s.add_dependency 'tilt', '~> 1.4'
20
20
  s.add_development_dependency 'rack-test', '~> 0.6'
21
21
  s.add_development_dependency 'rspec', '~> 2.9'
22
+ s.add_development_dependency 'rake', '>= 10'
22
23
  end
@@ -166,7 +166,7 @@ module Scorched
166
166
  end
167
167
 
168
168
  it "executes route only if all conditions return true" do
169
- app << {pattern: '/', conditions: {method: 'POST'}, target: generic_handler}
169
+ app << {pattern: '/$', conditions: {method: 'POST'}, target: generic_handler}
170
170
  response = rt.get "/"
171
171
  response.status.should be_between(400, 499)
172
172
  response = rt.post "/"
@@ -582,13 +582,24 @@ module Scorched
582
582
  rt.get('/sub').body.should == 'hello there'
583
583
  end
584
584
 
585
- it "passing within filter of root controller results in uncaught symbol" do
585
+ it "results in uncaught symbol if passing within filter of root controller " do
586
586
  app.before { pass }
587
587
  expect {
588
588
  app.get('/') { }
589
589
  rt.get('/')
590
590
  }.to raise_error(ArgumentError)
591
591
  end
592
+
593
+ it "is not considered a match if a mapping passes the request" do
594
+ app.get('/*') { pass }
595
+ app.get('/nopass') { }
596
+ handled = nil
597
+ app.after { handled = @_handled }
598
+ rt.get('/').status.should == 404 # 404 if matched, but passed
599
+ handled.should_not be_true
600
+ rt.get('/nopass').status.should == 200
601
+ handled.should be_true
602
+ end
592
603
  end
593
604
 
594
605
  describe "status codes" do
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.13'
4
+ version: '0.14'
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-06-14 00:00:00.000000000 Z
11
+ date: 2013-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '10'
83
97
  description: A light-weight Sinatra-inspired web framework for web sites and applications
84
98
  of any size.
85
99
  email: tom@tomwardrop.com
@@ -91,6 +105,7 @@ files:
91
105
  - Gemfile
92
106
  - LICENSE
93
107
  - README.md
108
+ - Rakefile
94
109
  - TODO.md
95
110
  - docs/01_preface.md
96
111
  - docs/02_fundamentals/01_the_controller.md
@@ -108,6 +123,7 @@ files:
108
123
  - docs/03_further_reading/running_unit_tests.md
109
124
  - examples/file_upload.ru
110
125
  - examples/media_types.ru
126
+ - examples/test.ru
111
127
  - lib/scorched.rb
112
128
  - lib/scorched/collection.rb
113
129
  - lib/scorched/controller.rb