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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76cdf68418dfc6310bff3b868bd2c9c170f758e4
4
- data.tar.gz: c2b1c2e3bfa9b35ff82f471d4e05e47bc75d162f
3
+ metadata.gz: 093564d10255044cd27165fa2d313495302037f7
4
+ data.tar.gz: 997dee45c86d07b9b63cc8fadf2bf00f398015ec
5
5
  SHA512:
6
- metadata.gz: e8c96d40213a62519ffa4e68bfe545b252ce93dcf8f0f5548941fb3169dc86b89e1c3c257ed1e5e33bef452c0fae90b2dd22bda1f07398602c767d85f422fda1
7
- data.tar.gz: 2ea78edc573c77a82cdf6431c456710aa50d0d38721bd7298396a4bfe28fa9bdd0a1b169600e6d4bb4e11901374548eb6d4b33338efb2bea8160cb2eb6475702
6
+ metadata.gz: bee6a1bfad4bd7e4c37ef9cdbcbafad13e56acbfe31056d015a906c6e12db77f247faa4a68165c33eead627c1ebe5f1289a310a344101d68644962783918ffc0
7
+ data.tar.gz: 46ab509c110aca5906ab448a04744d4c0623e1bc182360b950bfd61f000c5805381f48d646526c6404608850b830d6fb0252d9908ebf123023b08fbe300df898
data/.gitignore CHANGED
@@ -18,3 +18,4 @@ spec/reports
18
18
  test/tmp
19
19
  test/version_tmp
20
20
  tmp
21
+ .DS_Store
@@ -2,8 +2,8 @@
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.1
5
6
  - jruby-19mode
6
- - jruby-20mode
7
7
 
8
8
  branches:
9
9
  only:
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 3.4.1
2
+ - Fix a bug when a NYNY app is used inside a namespace
3
+
1
4
  3.4.0
2
5
  - Fix constraint matching
3
6
  - Add constraints class method to group constraints
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
- ``ruby
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
 
@@ -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?
@@ -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 :builder, Rack::Builder.new
12
- inheritable :scope_class, Class.new(RequestScope)
13
- inheritable :route_defs, []
14
- inheritable :before_hooks, []
15
- inheritable :after_hooks, []
16
- inheritable :before_init_hooks, []
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.builder.run Router.new({
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 = self.class.builder.to_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
- builder.use middleware, *args, &block
94
+ middlewares << [middleware, args, block]
78
95
  end
79
96
 
80
97
  def register *extensions
@@ -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.send "#{attr}=", self.send(attr).clone
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
@@ -1,3 +1,3 @@
1
1
  module NYNY
2
- VERSION = "3.4.0"
2
+ VERSION = "3.4.1"
3
3
  end
@@ -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
@@ -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
- kls = mock_app_class
220
- kls.builder.should_receive(:use).with(NullMiddleware)
221
- kls.use(NullMiddleware)
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
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe NYNY do
4
- its 'root points to pwd' do
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
- its 'root can join a path' do
12
+ it 'root can join a path' do
13
13
  NYNY.root.join("foo").should == Pathname.pwd + "foo"
14
14
  end
15
15
  end
@@ -49,6 +49,7 @@ class NullMiddleware
49
49
  end
50
50
 
51
51
  def call env
52
+ env['NULL'] = true
52
53
  @app.call env
53
54
  end
54
55
  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: 3.4.0
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-04-13 00:00:00.000000000 Z
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: '0'
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: '0'
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