nyny 1.0.0 → 1.0.1

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: 7d06702b70c5c8ae2b5b41dec0c6cdddd867e2cc
4
- data.tar.gz: 771e4872192c8727b722181153822df8dd379985
3
+ metadata.gz: cc338178211fc422842846bf3bb23284b8e4924e
4
+ data.tar.gz: 16dedfbf23305f2e6bbf4e041b01b53b5b63e2d6
5
5
  SHA512:
6
- metadata.gz: 20c1401e48e5dd9a690c084ac040bdf705db169f765ea4203ed7bcc9cc63149f2153d4a1f8a96bb6b0d12d4c3007ed39c36f4e353fcb5da7318814580347e163
7
- data.tar.gz: 9bdd755fcd18570974ce27564a605618f8dd3ea944111d74c55268b86879a85e320c9672be7738d1d99a9edcfeb390ee398adcb0a9fcffd1afdcbb40d77c8f7c
6
+ metadata.gz: 950ce1b36a87d5da3d6fabb67c223a16c09016b32e381843b71e3028eb4456171204cdf4ab43e461a7b3cb9243c00dfb1359d1be9fa370a7e8e005cf6ecb9af4
7
+ data.tar.gz: abf1e6dcbf3ccd5e62a6af7ec21666f0f8c7f0b85d4fd0a512fa439cd36e1e47a620f616d2badd410ac97d637d5e39bd08949819231a3635ce61c25c0228ed69
@@ -1,6 +1,7 @@
1
1
  module NYNY
2
2
  class RequestScope
3
3
  attr_reader :request, :response
4
+ HaltError = Class.new(StandardError)
4
5
 
5
6
  def self.add_helper_module m
6
7
  include m
@@ -33,21 +34,17 @@ module NYNY
33
34
  end
34
35
 
35
36
  def halt status, headers={}, body=''
36
- @halt_response = Response.new body, status, @headers.merge(headers)
37
+ throw :halt, Response.new(body, status, @headers.merge(headers))
37
38
  end
38
39
 
39
- def redirect_to path
40
- @redirect = path
40
+ def redirect_to uri, status=302
41
+ halt status, {'Location' => uri}
41
42
  end
43
+ alias_method :redirect, :redirect_to
42
44
 
43
45
  def apply_to &handler
44
- @response = @halt_response || begin
45
- Response.new instance_eval(&handler), @status, @headers
46
- end
47
-
46
+ @response = Response.new instance_eval(&handler), @status, @headers
48
47
  cookies.each {|k,v| @response.set_cookie k,v }
49
- @response.redirect(@redirect) if @redirect
50
- @response.finish
51
48
  @response
52
49
  end
53
50
  end
data/lib/nyny/router.rb CHANGED
@@ -24,21 +24,26 @@ module NYNY
24
24
  handler, params = find_handler req
25
25
 
26
26
  if handler != NullHandler
27
- process req, handler, params
27
+ prepare_params req, params
28
+ process req, handler
28
29
  else
29
30
  fallback.call env
30
31
  end
31
32
  end
32
33
 
33
- def process request, handler, url_params
34
+ def prepare_params request, url_params
34
35
  request.params.merge! url_params
35
36
  request.params.default_proc = proc {|h,k| h[k.to_s] || h[k.to_sym]}
37
+ end
36
38
 
39
+ def process request, handler
37
40
  scope = RequestScope.new(request)
38
- before_hooks.each {|h| scope.instance_eval &h }
39
- response = scope.apply_to &handler
40
- after_hooks.each {|h| scope.instance_eval &h }
41
- response
41
+ catch (:halt) do
42
+ before_hooks.each {|h| scope.instance_eval &h }
43
+ response = scope.apply_to &handler
44
+ after_hooks.each {|h| scope.instance_eval &h }
45
+ response
46
+ end
42
47
  end
43
48
  end
44
49
  end
data/lib/nyny/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module NYNY
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/nyny.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["andrei.lisnic@gmail.com"]
11
11
  spec.description = %q{New York, New York - (very) small Sinatra clone.}
12
12
  spec.summary = %q{New York, New York.}
13
- spec.homepage = "https://github.com/alisnic/nyny"
13
+ spec.homepage = "http://alisnic.github.io/nyny/"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -66,9 +66,33 @@ describe RequestScope do
66
66
  prc.should_not_receive(:call)
67
67
  end
68
68
 
69
+ it 'should halt if the statement is in the route definition' do
70
+ app = mock_app do
71
+ get '/' do
72
+ halt 200, {}, 'Halted'
73
+ 'shouldnt be returned'
74
+ end
75
+ end
76
+ res = app.get '/'
77
+ res.status.should == 200
78
+ res.body.should == 'Halted'
79
+ end
80
+
81
+ it 'return prematurely with pass' do
82
+ app = mock_app do
83
+ get '/' do
84
+ next 'hui'
85
+ 'shouldnt be returned'
86
+ end
87
+ end
88
+ res = app.get '/'
89
+ res.status.should == 200
90
+ res.body.should == 'hui'
91
+ end
92
+
69
93
  it '#redirect_to should redirect' do
70
94
  redir = Proc.new { redirect_to 'http://foo.bar' }
71
- response = subject.apply_to &redir
95
+ response = catch(:halt) { subject.apply_to &redir }
72
96
  response.status.should == 302
73
97
  response.headers['Location'].should == 'http://foo.bar'
74
98
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nyny
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Lisnic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-26 00:00:00.000000000 Z
11
+ date: 2013-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,7 +113,7 @@ files:
113
113
  - spec/route_signature_spec.rb
114
114
  - spec/runner_spec.rb
115
115
  - spec/spec_helper.rb
116
- homepage: https://github.com/alisnic/nyny
116
+ homepage: http://alisnic.github.io/nyny/
117
117
  licenses:
118
118
  - MIT
119
119
  metadata: {}