nyny 1.0.0 → 1.0.1
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 +4 -4
- data/lib/nyny/request_scope.rb +6 -9
- data/lib/nyny/router.rb +11 -6
- data/lib/nyny/version.rb +1 -1
- data/nyny.gemspec +1 -1
- data/spec/request_scope_spec.rb +25 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc338178211fc422842846bf3bb23284b8e4924e
|
4
|
+
data.tar.gz: 16dedfbf23305f2e6bbf4e041b01b53b5b63e2d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 950ce1b36a87d5da3d6fabb67c223a16c09016b32e381843b71e3028eb4456171204cdf4ab43e461a7b3cb9243c00dfb1359d1be9fa370a7e8e005cf6ecb9af4
|
7
|
+
data.tar.gz: abf1e6dcbf3ccd5e62a6af7ec21666f0f8c7f0b85d4fd0a512fa439cd36e1e47a620f616d2badd410ac97d637d5e39bd08949819231a3635ce61c25c0228ed69
|
data/lib/nyny/request_scope.rb
CHANGED
@@ -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
|
-
|
37
|
+
throw :halt, Response.new(body, status, @headers.merge(headers))
|
37
38
|
end
|
38
39
|
|
39
|
-
def redirect_to
|
40
|
-
|
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 = @
|
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
|
-
|
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
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
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 = "
|
13
|
+
spec.homepage = "http://alisnic.github.io/nyny/"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
data/spec/request_scope_spec.rb
CHANGED
@@ -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.
|
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-
|
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:
|
116
|
+
homepage: http://alisnic.github.io/nyny/
|
117
117
|
licenses:
|
118
118
|
- MIT
|
119
119
|
metadata: {}
|