nyny 3.4.0 → 3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/CHANGELOG +3 -0
- data/README.md +1 -5
- data/lib/nyny/app.rb +0 -11
- data/lib/nyny/base.rb +27 -10
- data/lib/nyny/primitives.rb +2 -3
- data/lib/nyny/version.rb +1 -1
- data/nyny.gemspec +1 -1
- data/spec/app_spec.rb +9 -48
- data/spec/namespace_spec.rb +63 -0
- data/spec/nyny_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 093564d10255044cd27165fa2d313495302037f7
|
4
|
+
data.tar.gz: 997dee45c86d07b9b63cc8fadf2bf00f398015ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bee6a1bfad4bd7e4c37ef9cdbcbafad13e56acbfe31056d015a906c6e12db77f247faa4a68165c33eead627c1ebe5f1289a310a344101d68644962783918ffc0
|
7
|
+
data.tar.gz: 46ab509c110aca5906ab448a04744d4c0623e1bc182360b950bfd61f000c5805381f48d646526c6404608850b830d6fb0252d9908ebf123023b08fbe300df898
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -209,7 +209,7 @@ That means that the route from above will match only if
|
|
209
209
|
|
210
210
|
To group multiple routes for a single constraint, use the constraints block:
|
211
211
|
|
212
|
-
|
212
|
+
```ruby
|
213
213
|
class App < NYNY::App
|
214
214
|
constraints :content_type => 'text/html' do
|
215
215
|
get '/' do
|
@@ -448,10 +448,6 @@ Optionally, an extension can add a `registered` method, which will be invoked
|
|
448
448
|
once the extension is registered. That method will be called with the app class
|
449
449
|
as a parameter.
|
450
450
|
|
451
|
-
Since NYNY has the same extension interface as Sinatra, some Sinatra extensions
|
452
|
-
might work with NYNY, although that is not guaranteed. However, an extension
|
453
|
-
written for NYNY will always work with Sinatra. (Forward compatible)
|
454
|
-
|
455
451
|
# F. A. Q.
|
456
452
|
TBD.
|
457
453
|
|
data/lib/nyny/app.rb
CHANGED
@@ -16,17 +16,6 @@ module NYNY
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def namespace url, &block
|
20
|
-
scope = self.scope_class
|
21
|
-
|
22
|
-
klass = Class.new self.superclass do
|
23
|
-
self.scope_class = scope
|
24
|
-
class_eval(&block)
|
25
|
-
end
|
26
|
-
|
27
|
-
builder.map (url) { use klass }
|
28
|
-
end
|
29
|
-
|
30
19
|
def run! port=9292
|
31
20
|
use Rack::CommonLogger
|
32
21
|
use BetterErrors::Middleware unless NYNY.env.production?
|
data/lib/nyny/base.rb
CHANGED
@@ -8,19 +8,27 @@ module NYNY
|
|
8
8
|
include NYNY::Inheritable
|
9
9
|
HTTP_VERBS = [:delete, :get, :head, :options, :patch, :post, :put, :trace]
|
10
10
|
|
11
|
-
inheritable :
|
12
|
-
inheritable :
|
13
|
-
inheritable :
|
14
|
-
inheritable :
|
15
|
-
inheritable :
|
16
|
-
inheritable :
|
17
|
-
inheritable :after_init_hooks, []
|
11
|
+
inheritable :scope_class, Class.new(RequestScope)
|
12
|
+
inheritable :route_defs, []
|
13
|
+
inheritable :before_hooks, []
|
14
|
+
inheritable :after_hooks, []
|
15
|
+
inheritable :before_init_hooks, []
|
16
|
+
inheritable :after_init_hooks, []
|
18
17
|
inheritable :default_constraints, {}
|
18
|
+
inheritable :middlewares, []
|
19
|
+
inheritable :map, {}
|
19
20
|
|
20
21
|
def initialize app=nil
|
22
|
+
builder = Rack::Builder.new
|
23
|
+
|
21
24
|
self.class.before_init_hooks.each {|h| h.call(self)}
|
22
25
|
|
23
|
-
self.class.
|
26
|
+
self.class.middlewares.each do |m, args, blk|
|
27
|
+
builder.use m, *args, &blk
|
28
|
+
end
|
29
|
+
self.class.map.each {|url, klass| builder.map(url) { use klass } }
|
30
|
+
|
31
|
+
builder.run Router.new({
|
24
32
|
:scope_class => self.class.scope_class,
|
25
33
|
:route_defs => self.class.route_defs,
|
26
34
|
:before_hooks => self.class.before_hooks,
|
@@ -28,7 +36,7 @@ module NYNY
|
|
28
36
|
:fallback => app
|
29
37
|
})
|
30
38
|
|
31
|
-
@app =
|
39
|
+
@app = builder.to_app
|
32
40
|
self.class.after_init_hooks.each {|h| h.call(self, @app)}
|
33
41
|
end
|
34
42
|
|
@@ -46,6 +54,15 @@ module NYNY
|
|
46
54
|
end
|
47
55
|
end
|
48
56
|
|
57
|
+
def namespace url, &block
|
58
|
+
scope = self.scope_class
|
59
|
+
|
60
|
+
map[url] = Class.new self.superclass do
|
61
|
+
self.scope_class = scope
|
62
|
+
class_eval(&block)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
49
66
|
def define_route path, options, &block
|
50
67
|
self.route_defs << [path, options, Proc.new(&block)]
|
51
68
|
end
|
@@ -74,7 +91,7 @@ module NYNY
|
|
74
91
|
end
|
75
92
|
|
76
93
|
def use middleware, *args, &block
|
77
|
-
|
94
|
+
middlewares << [middleware, args, block]
|
78
95
|
end
|
79
96
|
|
80
97
|
def register *extensions
|
data/lib/nyny/primitives.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support/hash_with_indifferent_access'
|
2
|
+
require 'active_support/core_ext/object/deep_dup'
|
2
3
|
require 'pathname'
|
3
4
|
|
4
5
|
module NYNY
|
@@ -14,10 +15,8 @@ module NYNY
|
|
14
15
|
|
15
16
|
def self.inherited subclass
|
16
17
|
@_inheritables.each do |attr|
|
17
|
-
subclass.
|
18
|
-
subclass.instance_variable_set "@_inheritables", @_inheritables.clone
|
18
|
+
subclass.inheritable attr, self.send(attr).deep_dup
|
19
19
|
end
|
20
|
-
super
|
21
20
|
end
|
22
21
|
end
|
23
22
|
end
|
data/lib/nyny/version.rb
CHANGED
data/nyny.gemspec
CHANGED
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_dependency "actionpack", "~> 4.0.2"
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
26
26
|
spec.add_development_dependency "rake"
|
27
|
-
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "rspec", "~> 2.14.1"
|
28
28
|
end
|
data/spec/app_spec.rb
CHANGED
@@ -47,50 +47,6 @@ describe App do
|
|
47
47
|
kls.should respond_to(:foo)
|
48
48
|
end
|
49
49
|
|
50
|
-
describe 'namespace' do
|
51
|
-
let (:app) do
|
52
|
-
mock_app do
|
53
|
-
helpers do
|
54
|
-
def le_helper
|
55
|
-
:lulwut
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
namespace '/foo' do
|
60
|
-
get '/' do
|
61
|
-
le_helper.should == :lulwut
|
62
|
-
'bar'
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
namespace '/nested' do
|
67
|
-
namespace '/space' do
|
68
|
-
get '/' do
|
69
|
-
le_helper.should == :lulwut
|
70
|
-
'caramba'
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
get '/' do
|
76
|
-
'no namespace here'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'allows to specify stuff in namespaces' do
|
82
|
-
app.get('/foo').body.should == 'bar'
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'does not break the main app' do
|
86
|
-
app.get('/').body.should == 'no namespace here'
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'can be nested as well' do
|
90
|
-
app.get('/nested/space/').body.should == 'caramba'
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
50
|
it 'should call registered method on extension' do
|
95
51
|
module Foo
|
96
52
|
def self.registered app
|
@@ -214,11 +170,16 @@ describe App do
|
|
214
170
|
let (:app_class) { Class.new(App) }
|
215
171
|
|
216
172
|
describe 'middlewares' do
|
217
|
-
|
218
173
|
it 'delegates to builder' do
|
219
|
-
|
220
|
-
|
221
|
-
|
174
|
+
app = mock_app do
|
175
|
+
use NullMiddleware
|
176
|
+
|
177
|
+
get '/' do
|
178
|
+
request.env['NULL'].should == true
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
app.get('/')
|
222
183
|
end
|
223
184
|
end
|
224
185
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NYNY::App do
|
4
|
+
describe 'namespace' do
|
5
|
+
let (:app) do
|
6
|
+
mock_app do
|
7
|
+
helpers do
|
8
|
+
def le_helper
|
9
|
+
:lulwut
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
namespace '/foo' do
|
14
|
+
get '/' do
|
15
|
+
le_helper.should == :lulwut
|
16
|
+
'bar'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
namespace '/nested' do
|
21
|
+
namespace '/space' do
|
22
|
+
get '/' do
|
23
|
+
le_helper.should == :lulwut
|
24
|
+
'caramba'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
get '/' do
|
30
|
+
'no namespace here'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'allows to use middlewares inside namespace' do
|
36
|
+
kls = Class.new(NYNY::Base) do
|
37
|
+
get '/' do
|
38
|
+
'foo'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
app = mock_app do
|
43
|
+
namespace '/foo' do
|
44
|
+
use kls
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
app.get('/foo')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'allows to specify stuff in namespaces' do
|
52
|
+
app.get('/foo').body.should == 'bar'
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'does not break the main app' do
|
56
|
+
app.get('/').body.should == 'no namespace here'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'can be nested as well' do
|
60
|
+
app.get('/nested/space/').body.should == 'caramba'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/nyny_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe NYNY do
|
4
|
-
|
4
|
+
it 'root points to pwd' do
|
5
5
|
NYNY.root.should == Pathname.pwd
|
6
6
|
end
|
7
7
|
|
@@ -9,7 +9,7 @@ describe NYNY do
|
|
9
9
|
NYNY.env.should be_test
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
it 'root can join a path' do
|
13
13
|
NYNY.root.join("foo").should == Pathname.pwd + "foo"
|
14
14
|
end
|
15
15
|
end
|
data/spec/spec_helper.rb
CHANGED
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: 3.4.
|
4
|
+
version: 3.4.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: 2014-
|
11
|
+
date: 2014-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack-contrib
|
@@ -98,16 +98,16 @@ dependencies:
|
|
98
98
|
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 2.14.1
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 2.14.1
|
111
111
|
description: New York, New York - a (ridiculously) small and powerful web framework.
|
112
112
|
email:
|
113
113
|
- andrei.lisnic@gmail.com
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- spec/config_spec.rb
|
138
138
|
- spec/inheritance_spec.rb
|
139
139
|
- spec/initialize_hooks_spec.rb
|
140
|
+
- spec/namespace_spec.rb
|
140
141
|
- spec/nyny_spec.rb
|
141
142
|
- spec/request_scope_spec.rb
|
142
143
|
- spec/runner_spec.rb
|
@@ -175,6 +176,7 @@ test_files:
|
|
175
176
|
- spec/config_spec.rb
|
176
177
|
- spec/inheritance_spec.rb
|
177
178
|
- spec/initialize_hooks_spec.rb
|
179
|
+
- spec/namespace_spec.rb
|
178
180
|
- spec/nyny_spec.rb
|
179
181
|
- spec/request_scope_spec.rb
|
180
182
|
- spec/runner_spec.rb
|