rack-app 0.14.0 → 0.15.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32dc4d9b8547ea72c4dbedc26574c6f656e5964a
4
- data.tar.gz: a1e719b055a7c201abbeb6cd0b9d7dc603ba966a
3
+ metadata.gz: a6a2ae4ec74c639f9e3d049458b89e08a62ef5c3
4
+ data.tar.gz: fdb0219ee8797b4d7aa221a9ca9871bddd6c7c55
5
5
  SHA512:
6
- metadata.gz: b177de5e0036bbc20ced07f3cbefc78ff49cd06d56ae3aad89235169aa972f9ae53906cfc7b89ea94ec14b4c2bea409d466ea288a03cb2af7037a301c4c5a50b
7
- data.tar.gz: 308fed5ee5aff8145a6d8fc52d865e3e0df32dfe05001ec7df939869b4dee2f5239d8c34c4eeaa53957dc26d0aa9c0b4fa68ec2b78eec8bccfacef7e672290e6
6
+ metadata.gz: 6d42439314b717b812de25cb5b393650d11dd964502dd00c20dbed8d49c69ed9d932107c4da4e0e626caf26ba8dec9c2c0cfa57f9943516934ab93823dc7eb5c
7
+ data.tar.gz: bdb3c7f423901de46b64ccdac7c945e895e0bcc9b7d5183aa4bcf9a9771392202c1be199d7779180a590251a0b2356f4b999797788717fc4f1e72374a0df05ec
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # [Rack::App](http://rack-app.com/) [![Build Status][travis-image]][travis-link]
2
2
 
3
- [travis-image]: https://secure.travis-ci.org/adamluzsi/rack-app.rb.png?branch=master
4
- [travis-link]: http://travis-ci.org/adamluzsi/rack-app.rb
3
+ [travis-image]: https://travis-ci.org/rack-app/rack-app.svg?branch=master
4
+ [travis-link]: http://travis-ci.org/rack-app/rack-app
5
5
  [travis-home]: http://travis-ci.org/
6
6
 
7
7
  ![Rack::App](http://rack-app-website.herokuapp.com/image/msruby_new.png)
@@ -39,28 +39,70 @@ Or install it yourself as:
39
39
  ## Usage
40
40
 
41
41
  config.ru
42
+
43
+ #### basic
44
+
45
+ ```ruby
46
+
47
+ require './bootstrap.rb'
48
+
49
+ class App < Rack::App
50
+
51
+ desc 'some hello endpoint'
52
+ get '/hello' do
53
+ 'Hello World!'
54
+ end
55
+
56
+ end
57
+
58
+ ```
59
+
60
+ #### complex
61
+
42
62
  ```ruby
43
63
 
44
- require 'rack/app'
64
+ require './bootstrap.rb'
65
+
66
+ class App < Rack::App
67
+
68
+ mount SomeAppClass
45
69
 
46
- class YourAwesomeApp < Rack::App
70
+ headers 'Access-Control-Allow-Origin' => '*',
71
+ 'Access-Control-Expose-Headers' => 'X-My-Custom-Header, X-Another-Custom-Header'
47
72
 
73
+ serializer do |object|
74
+ object.to_s
75
+ end
76
+
77
+ desc 'some hello endpoint'
48
78
  get '/hello' do
49
79
  'Hello World!'
50
80
  end
51
81
 
82
+ desc 'some restful endpoint'
52
83
  get '/users/:user_id' do
84
+ response.status = 201
53
85
  params['user_id'] #=> restful parameter :user_id
54
- say #=> "hello world!"
55
- end
56
-
86
+ say #=> "hello world!"
87
+ end
88
+
89
+ desc 'some endpoint that has error and will be rescued'
90
+ get '/make_error' do
91
+ raise(StandardError,'error block rescued')
92
+ end
93
+
94
+
57
95
  def say
58
- 'hello world!'
59
- end
60
-
61
- end
96
+ "hello #{params['user_id']}!"
97
+ end
98
+
99
+ error StandardError, NoMethodError do |ex|
100
+ {:error=>ex.message}
101
+ end
62
102
 
63
- run YourAwesomeApp
103
+ root '/hello'
104
+
105
+ end
64
106
 
65
107
  ```
66
108
 
@@ -78,37 +120,53 @@ for testing use rack/test or the bundled testing module for writing unit test fo
78
120
  require 'spec_helper'
79
121
  require 'rack/app/test'
80
122
 
81
- describe MyRackApp do
123
+ describe App do
82
124
 
83
125
  include Rack::App::Test
84
-
126
+
85
127
  rack_app described_class
86
-
87
- describe '#something' do
88
-
89
- subject{ get(url: '/hello', params: {'dog' => 'meat'}, headers: {'X-Cat' => 'fur'}) }
90
128
 
91
- it { expect(subject.body).to eq ['world']}
92
-
129
+ describe '/hello' do
130
+ # example for params and headers and payload use
131
+ subject{ get(url: '/hello', params: {'dog' => 'meat'}, headers: {'X-Cat' => 'fur'}, payload: 'some string') }
132
+
133
+ it { expect(subject.status).to eq 200 }
134
+
135
+ it { expect(subject.body.join).to eq "Hello World!" }
136
+ end
137
+
138
+ describe '/users/:user_id' do
139
+ # restful endpoint example
140
+ subject{ get(url: '/users/1234') }
141
+
142
+ it { expect(subject.body.join).to eq 'hello 1234!'}
143
+
93
144
  it { expect(subject.status).to eq 201 }
94
-
95
- end
96
-
97
- end
145
+
146
+ end
147
+
148
+ describe '/make_error' do
149
+ # error handled example
150
+ subject{ get(url: '/make_error') }
151
+
152
+ it { expect(subject.body.join).to eq '{:error=>"error block rescued"}' }
153
+ end
154
+
155
+ end
156
+
98
157
 
99
158
  ```
100
159
 
101
160
  ## Example Apps To start with
102
161
 
103
- * [Basic](https://github.com/adamluzsi/rack-app.rb-examples/tree/master/basic)
162
+ * [Basic](https://github.com/rack-app/rack-app-example-basic)
104
163
  * bare bone simple example app
105
164
 
106
- * [Escher Authorized Api](https://github.com/adamluzsi/rack-app.rb-examples/tree/master/escher_authorized)
165
+ * [Escher Authorized Api](https://github.com/rack-app/rack-app-example-escher)
107
166
  * complex authorization for corporal level api use
108
167
 
109
168
  ## [Benchmarking](https://github.com/adamluzsi/rack-app.rb-benchmark)
110
169
 
111
-
112
170
  * Dump duration with zero business logic or routing: 2.4184169999892074e-06 s
113
171
  * no routing
114
172
  * return only a static array with static values
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.14.0
1
+ 0.15.0
@@ -27,7 +27,7 @@ class Rack::App::Endpoint
27
27
  request_handler.response = response
28
28
  request.env['rack.app.path_params_matcher']= @path_params_matcher.dup
29
29
 
30
- call_return = @error_handler.execute_with_error_handling { request_handler.instance_exec(&@logic_block) }
30
+ call_return = @error_handler.execute_with_error_handling_for(request_handler,&@logic_block)
31
31
 
32
32
  return call_return if is_a_rack_response_finish?(call_return)
33
33
  add_response_body_if_missing(call_return, response)
@@ -11,10 +11,10 @@ class Rack::App::ErrorHandler
11
11
  nil
12
12
  end
13
13
 
14
- def execute_with_error_handling
15
- yield
14
+ def execute_with_error_handling_for(instance, &block)
15
+ instance.instance_exec(&block)
16
16
  rescue *[Exception, @handlers.keys].flatten => ex
17
- get_handler(ex).call(ex)
17
+ instance.instance_exec(ex, &get_handler(ex))
18
18
  end
19
19
 
20
20
  protected
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-02-07 00:00:00.000000000 Z
12
+ date: 2016-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler