nyny 3.3.1 → 3.4.0

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: 6db6a9ca35676823e643db65bc2b458c44bc793f
4
- data.tar.gz: 582642543e721156d818975ced8ad08849c5c2eb
3
+ metadata.gz: 76cdf68418dfc6310bff3b868bd2c9c170f758e4
4
+ data.tar.gz: c2b1c2e3bfa9b35ff82f471d4e05e47bc75d162f
5
5
  SHA512:
6
- metadata.gz: 0b4aeb7be4451c4d4663cecf2ce4bb0056bf9a2170d2afd0935399f0d114c37a32fb5f3101029509a839dee046d809fbf3dfd48a52faaa5b996c18d006cc3dfc
7
- data.tar.gz: fc5e89993a3d8356c21fab47ca10b132ca1b0eeb1f5e46b7365f648353b35b8bfbfd873e2ec30a4a19717d191c63adfda8404c01fcc70708b203977b4ff53d23
6
+ metadata.gz: e8c96d40213a62519ffa4e68bfe545b252ce93dcf8f0f5548941fb3169dc86b89e1c3c257ed1e5e33bef452c0fae90b2dd22bda1f07398602c767d85f422fda1
7
+ data.tar.gz: 2ea78edc573c77a82cdf6431c456710aa50d0d38721bd7298396a4bfe28fa9bdd0a1b169600e6d4bb4e11901374548eb6d4b33338efb2bea8160cb2eb6475702
data/CHANGELOG CHANGED
@@ -1,81 +1,85 @@
1
+ 3.4.0
2
+ - Fix constraint matching
3
+ - Add constraints class method to group constraints
4
+
1
5
  3.3.1
2
- - if the response of the route is a enumerable, NYNY will try to
3
- send it in chunks (given that both the client and the server support it)
4
- - NYNY::Base for those who love the barebone (lacks config, namespaces,
5
- templates, and run!)
6
+ - if the response of the route is a enumerable, NYNY will try to
7
+ send it in chunks (given that both the client and the server support it)
8
+ - NYNY::Base for those who love the barebone (lacks config, namespaces,
9
+ templates, and run!)
6
10
 
7
11
  3.3.0
8
- - App.config
9
- - before_initialize hooks
10
- - after_initialize hooks
12
+ - App.config
13
+ - before_initialize hooks
14
+ - after_initialize hooks
11
15
 
12
16
  3.2.2
13
- - Use Journey directly from ActionDispatch, since rails/journey is obsolete
14
- - Fix indifferent nested params
15
- - Make helpers accessible inside namespaces
16
- - Fix namespaces inheritance behaviour
17
+ - Use Journey directly from ActionDispatch, since rails/journey is obsolete
18
+ - Fix indifferent nested params
19
+ - Make helpers accessible inside namespaces
20
+ - Fix namespaces inheritance behaviour
17
21
 
18
22
  3.2.1
19
- - Fallback to Tilt 1.4.1 since 2.0.0 has conflicts with a lot
20
- of gems
21
- - Improved and fixed the outdated examples
23
+ - Fallback to Tilt 1.4.1 since 2.0.0 has conflicts with a lot
24
+ of gems
25
+ - Improved and fixed the outdated examples
22
26
 
23
27
  3.2.0
24
- - Use Rails' Journey router as router to conquer the world and shorten
25
- the codebase
28
+ - Use Rails' Journey router as router to conquer the world and shorten
29
+ the codebase
26
30
 
27
31
  3.1.0
28
- - use latest Tilt (2.0.0)
29
- - get rid of silly Rack::Response hacks, write to body properly
30
- - Response#rewrite (body= aliases it for backward compatibility)
31
- - Refactor .run! implementation, prefer thin, webrik.
32
- - NYNY now ships with better_errors, which is only enabled in development
33
- - Fixed builder instanciation logic
34
- - removed benchmark script, since tilt dep version is not compatible with
35
- Sinatra
32
+ - use latest Tilt (2.0.0)
33
+ - get rid of silly Rack::Response hacks, write to body properly
34
+ - Response#rewrite (body= aliases it for backward compatibility)
35
+ - Refactor .run! implementation, prefer thin, webrik.
36
+ - NYNY now ships with better_errors, which is only enabled in development
37
+ - Fixed builder instanciation logic
38
+ - removed benchmark script, since tilt dep version is not compatible with
39
+ Sinatra
36
40
 
37
41
  3.0.1
38
- - File SystemStackError when accessing missing param (@holies)
42
+ - File SystemStackError when accessing missing param (@holies)
39
43
 
40
44
  3.0.0
41
- - Use Rack builder to shorten and simplify the code
42
- - Add support for namespaces by using the builder
43
- - Add ruby-prof as a development dependency
44
- - NYNY will return a Rack-like response on each request ([status, headers, body])
45
- - headers behave like a hash
46
- - cookies behave like a hash
47
- - added sprockets integration example
48
- - improved documentation
49
- - Fixed inheritance behaviour for App (routes, filters, helpers, middlewares
50
- will be passed down the inheritance chain)
45
+ - Use Rack builder to shorten and simplify the code
46
+ - Add support for namespaces by using the builder
47
+ - Add ruby-prof as a development dependency
48
+ - NYNY will return a Rack-like response on each request ([status, headers, body])
49
+ - headers behave like a hash
50
+ - cookies behave like a hash
51
+ - added sprockets integration example
52
+ - improved documentation
53
+ - Fixed inheritance behaviour for App (routes, filters, helpers, middlewares
54
+ will be passed down the inheritance chain)
51
55
 
52
56
  2.2.1
53
- - Added support for templates
57
+ - Added support for templates
54
58
 
55
59
  2.1.1
56
- - After blocks will now be evaluated even if the request was halted
60
+ - After blocks will now be evaluated even if the request was halted
57
61
 
58
62
  2.1.0
59
- - Add ability to define helpers with a block
60
- - Remove benchmark folder, and create a single benchmark file which can be
61
- executed easily
62
- - Simplified and optimized routing logic
63
- - Fixed root path processing when a NYNY app is mounted
64
- - Added Rails interop example
65
- - Added session example
66
- - Added NYNY.root
67
- - Added NYNY.env
68
- - NYNY will not show exceptions in production env
63
+ - Add ability to define helpers with a block
64
+ - Remove benchmark folder, and create a single benchmark file which can be
65
+ executed easily
66
+ - Simplified and optimized routing logic
67
+ - Fixed root path processing when a NYNY app is mounted
68
+ - Added Rails interop example
69
+ - Added session example
70
+ - Added NYNY.root
71
+ - Added NYNY.env
72
+ - NYNY will not show exceptions in production env
69
73
 
70
74
  2.0.0
71
- - Simplified and improved RouteSignature implementation
72
- - Simplified and improved RequestScope implementation
73
- - Made response object available in RequestScope
74
- - removed .use_protection! (the rack-protection middleware can be easily
75
- used manually)
76
- - added support for extensions (using .register, which works the same way as in sinatra)
75
+ - Simplified and improved RouteSignature implementation
76
+ - Simplified and improved RequestScope implementation
77
+ - Made response object available in RequestScope
78
+ - removed .use_protection! (the rack-protection middleware can be easily
79
+ used manually)
80
+ - added support for extensions (using .register, which works the same way as in sinatra)
77
81
 
78
82
  1.0.2
79
- - Add rack to runtime deps (@etehtsea)
83
+ - Add rack to runtime deps (@etehtsea)
80
84
 
81
85
  1.0.0 Initial release
data/README.md CHANGED
@@ -108,7 +108,7 @@ true
108
108
  ## Configuration
109
109
  You can configure your app by attaching arbitrary properties to config object:
110
110
  ```ruby
111
- class App << NYNY::App
111
+ class App < NYNY::App
112
112
  config.foo = 'bar'
113
113
  end
114
114
 
@@ -197,12 +197,31 @@ Each route definition call optionally accepts constraints:
197
197
 
198
198
  ```ruby
199
199
  class App < NYNY::App
200
- get '/', :constraints => {:format => :html} do
200
+ get '/', :constraints => {:content_type => 'text/html'} do
201
201
  'html'
202
202
  end
203
203
  end
204
204
  ```
205
- You can use [the same constraints][constraints] you use in Rails.
205
+
206
+ What are constraints? Constraints are assertions on the request object.
207
+ That means that the route from above will match only if
208
+ `request.content_type` is 'text/html'.
209
+
210
+ To group multiple routes for a single constraint, use the constraints block:
211
+
212
+ ``ruby
213
+ class App < NYNY::App
214
+ constraints :content_type => 'text/html' do
215
+ get '/' do
216
+ 'html'
217
+ end
218
+
219
+ get '/foo' do
220
+ 'foo html'
221
+ end
222
+ end
223
+ end
224
+ ```
206
225
 
207
226
  Besides the constraints, you can specify defaults:
208
227
  ```ruby
@@ -224,8 +243,6 @@ This means that several methods/objects available inside that block:
224
243
  - `request` - A `Rack::Request` object which encapsulates the request
225
244
  to that route. (see [Rack::Request documentation][3] for more info)
226
245
  - `response` - A `Rack::Response` object which encapsulates the response.
227
- Additionally, NYNY's response exposes 2 more methods in addition to Rack's ones.
228
- (see [primitives.rb][primitivesrb])
229
246
  - `params` - a hash which contains both POST body params and GET querystring params.
230
247
  - `headers` - a hash with the response headers
231
248
  (ex: `headers['Content-Type'] = 'text/html'`)
@@ -34,4 +34,4 @@ module NYNY
34
34
  end
35
35
  end
36
36
  end
37
- end
37
+ end
@@ -15,6 +15,7 @@ module NYNY
15
15
  inheritable :after_hooks, []
16
16
  inheritable :before_init_hooks, []
17
17
  inheritable :after_init_hooks, []
18
+ inheritable :default_constraints, {}
18
19
 
19
20
  def initialize app=nil
20
21
  self.class.before_init_hooks.each {|h| h.call(self)}
@@ -39,7 +40,7 @@ module NYNY
39
40
  class << self
40
41
  HTTP_VERBS.each do |method|
41
42
  define_method method do |path, options={}, &block|
42
- options[:constraints] ||= {}
43
+ options[:constraints] = default_constraints.merge(options[:constraints] || {})
43
44
  options[:constraints].merge!(:request_method => method.to_s.upcase)
44
45
  define_route path, options, &block
45
46
  end
@@ -49,6 +50,13 @@ module NYNY
49
50
  self.route_defs << [path, options, Proc.new(&block)]
50
51
  end
51
52
 
53
+ def constraints args, &block
54
+ current = self.default_constraints.dup
55
+ self.default_constraints = args
56
+ instance_eval &block
57
+ self.default_constraints = current
58
+ end
59
+
52
60
  def before &blk
53
61
  before_hooks << Proc.new(&blk)
54
62
  end
@@ -29,7 +29,8 @@ module NYNY
29
29
  def prepare_for_journey route_defs
30
30
  routes = ActionDispatch::Journey::Routes.new
31
31
  @journey = ActionDispatch::Journey::Router.new(routes, {
32
- :parameters_key => 'nyny.params'
32
+ :parameters_key => 'nyny.params',
33
+ :request_class => NYNY::Request
33
34
  })
34
35
 
35
36
  route_defs.each do |path, options, handler|
@@ -58,4 +59,4 @@ module NYNY
58
59
  end
59
60
  end
60
61
  end
61
- end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module NYNY
2
- VERSION = "3.3.1"
2
+ VERSION = "3.4.0"
3
3
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = NYNY::VERSION
9
9
  spec.authors = ["Andrei Lisnic"]
10
10
  spec.email = ["andrei.lisnic@gmail.com"]
11
- spec.description = %q{New York, New York - (very) small Sinatra clone.}
11
+ spec.description = %q{New York, New York - a (ridiculously) small and powerful web framework.}
12
12
  spec.summary = %q{New York, New York.}
13
13
  spec.homepage = "http://alisnic.github.io/nyny/"
14
14
  spec.license = "MIT"
@@ -19,6 +19,23 @@ describe App do
19
19
  response.status.should == 404
20
20
  end
21
21
 
22
+ it 'can use constraints block' do
23
+ app = mock_app do
24
+ constraints :content_type => 'text/html' do
25
+ get '/' do
26
+ 'HTML!'
27
+ end
28
+ end
29
+
30
+ get '/' do
31
+ 'not html'
32
+ end
33
+ end
34
+
35
+ app.get('/').body.should == 'not html'
36
+ app.get('/', 'CONTENT_TYPE' => 'text/html').body.should == 'HTML!'
37
+ end
38
+
22
39
  it 'should able to register a extension' do
23
40
  module Foo
24
41
  def foo
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.3.1
4
+ version: 3.4.0
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-02-19 00:00:00.000000000 Z
11
+ date: 2014-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-contrib
@@ -108,7 +108,7 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description: New York, New York - (very) small Sinatra clone.
111
+ description: New York, New York - a (ridiculously) small and powerful web framework.
112
112
  email:
113
113
  - andrei.lisnic@gmail.com
114
114
  executables: []
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  version: '0'
167
167
  requirements: []
168
168
  rubyforge_project:
169
- rubygems_version: 2.2.0
169
+ rubygems_version: 2.2.2
170
170
  signing_key:
171
171
  specification_version: 4
172
172
  summary: New York, New York.