nyny 3.4.1 → 3.4.2
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/README.md +10 -0
- data/lib/nyny/base.rb +12 -9
- data/lib/nyny/version.rb +1 -1
- data/spec/namespace_spec.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39c4e5e1013febaf7a0b8d40202c2e2cbc481e6f
|
4
|
+
data.tar.gz: b2144b7cb42eaaa5135e2042b357b258df86765a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52e7699ecb41b50e5b8ac23cc7bd05b684b8a9c1df1cd7d8bc7b1374f261c1a2e406bec1038380e9dd8037342923d04188fa7d7852f79eef669b5a38eee41b73
|
7
|
+
data.tar.gz: 00b60be3b8df426424a3b6baae0bf52fdf7b7e07887933ebdc3f348754b39a7e6acd018c95071f56d7d5322dddb138767f58851e0489420afb0052d06926b81f
|
data/README.md
CHANGED
@@ -262,11 +262,21 @@ You can define namespaces for routes in NYNY. Each namespace is an isolated
|
|
262
262
|
app, which means that you can use the same api that you use in your top app there:
|
263
263
|
|
264
264
|
```ruby
|
265
|
+
class Ping < NYNY::App
|
266
|
+
get '/' do #this will be accessbile at '/ping'
|
267
|
+
'pong'
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
265
271
|
class App < NYNY::App
|
266
272
|
get '/' do
|
267
273
|
'Hello'
|
268
274
|
end
|
269
275
|
|
276
|
+
# You can pass a Rack app to the namespace
|
277
|
+
namespace '/ping', Ping
|
278
|
+
|
279
|
+
# Or you can pass a block, which will create the app for you
|
270
280
|
namespace '/nested' do
|
271
281
|
use SomeMiddleware
|
272
282
|
helpers SomeHelpers
|
data/lib/nyny/base.rb
CHANGED
@@ -19,15 +19,9 @@ module NYNY
|
|
19
19
|
inheritable :map, {}
|
20
20
|
|
21
21
|
def initialize app=nil
|
22
|
-
builder = Rack::Builder.new
|
23
|
-
|
24
22
|
self.class.before_init_hooks.each {|h| h.call(self)}
|
25
23
|
|
26
|
-
|
27
|
-
builder.use m, *args, &blk
|
28
|
-
end
|
29
|
-
self.class.map.each {|url, klass| builder.map(url) { use klass } }
|
30
|
-
|
24
|
+
builder = initialize_builder
|
31
25
|
builder.run Router.new({
|
32
26
|
:scope_class => self.class.scope_class,
|
33
27
|
:route_defs => self.class.route_defs,
|
@@ -40,6 +34,13 @@ module NYNY
|
|
40
34
|
self.class.after_init_hooks.each {|h| h.call(self, @app)}
|
41
35
|
end
|
42
36
|
|
37
|
+
def initialize_builder
|
38
|
+
builder = Rack::Builder.new
|
39
|
+
self.class.middlewares.each { |m, args, blk| builder.use m, *args, &blk }
|
40
|
+
self.class.map.each {|url, klass| builder.map(url) { use klass } }
|
41
|
+
builder
|
42
|
+
end
|
43
|
+
|
43
44
|
def call env
|
44
45
|
@app.call env
|
45
46
|
end
|
@@ -54,13 +55,15 @@ module NYNY
|
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
57
|
-
def namespace url, &block
|
58
|
+
def namespace url, app=nil, &block
|
58
59
|
scope = self.scope_class
|
59
60
|
|
60
|
-
|
61
|
+
app ||= Class.new self.superclass do
|
61
62
|
self.scope_class = scope
|
62
63
|
class_eval(&block)
|
63
64
|
end
|
65
|
+
|
66
|
+
map[url] = app
|
64
67
|
end
|
65
68
|
|
66
69
|
def define_route path, options, &block
|
data/lib/nyny/version.rb
CHANGED
data/spec/namespace_spec.rb
CHANGED
@@ -32,6 +32,25 @@ describe NYNY::App do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
it 'accepts a app as a parameter' do
|
36
|
+
mounted = mock_app_class do
|
37
|
+
get '/' do
|
38
|
+
'mounted!'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
app = mock_app do
|
43
|
+
namespace '/mounted', mounted
|
44
|
+
|
45
|
+
get '/' do
|
46
|
+
'root'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
app.get('/').body.should == 'root'
|
51
|
+
app.get('/mounted').body.should == 'mounted!'
|
52
|
+
end
|
53
|
+
|
35
54
|
it 'allows to use middlewares inside namespace' do
|
36
55
|
kls = Class.new(NYNY::Base) do
|
37
56
|
get '/' do
|
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.2
|
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-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack-contrib
|