rack-app 0.23.0 → 0.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -17
- data/VERSION +1 -1
- data/lib/rack/app.rb +64 -45
- data/lib/rack/app/error_handler.rb +2 -0
- data/lib/rack/app/serializer.rb +5 -3
- 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: 4540204d722b8a8095a57d0f842022290db437fb
|
4
|
+
data.tar.gz: 8460edbebc8ed290637f170d38304c8f45a2d21b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81b30a658e13d1b0cb920554eb5154d12f836095dabe2a35d0eefbb306dc70f6bd767f3bfd3ba5c6e3a9e305422a5631e2d59e4e42a9465ccb9a4192a7050f3a
|
7
|
+
data.tar.gz: 2799da05163d51508ece54fc6b8c5adbcc0177af9654dccae9233fa10df48c6b24e6b9d6c28e4f47255ec006158d2262f512c184787f76e226d15a0b2a0685e4
|
data/README.md
CHANGED
@@ -213,28 +213,33 @@ end
|
|
213
213
|
* [Escher Authorized Api](https://github.com/rack-app/rack-app-example-escher)
|
214
214
|
* complex authorization for corporal level api use
|
215
215
|
|
216
|
-
## [Benchmarking](https://github.com/
|
216
|
+
## [Benchmarking](https://github.com/rack-app/rack-app-benchmark)
|
217
217
|
|
218
218
|
the benchmarking was taken on the following hardware specification:
|
219
219
|
* Processor: 2,7 GHz Intel Core i5
|
220
220
|
* Memory: 16 GB 1867 MHz DDR3
|
221
221
|
* Ruby: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin15.0]
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
| hobbit | 0.6.1 |
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
222
|
+
|
223
|
+
### number of declared endpoints: 100
|
224
|
+
|
225
|
+
### number of declared endpoints: 100
|
226
|
+
|
227
|
+
| name | version | current / fastest | real |
|
228
|
+
| ---------------------- | ---------------------- | ---------------------- | ---------------------- |
|
229
|
+
| rack | 1.6.4 | 1.0 | 1.6755999999997824e-06 |
|
230
|
+
| rack-app | 0.23.0 | 12.949 | 2.169760000000045e-05 |
|
231
|
+
| ramaze | 2012.12.08 | 24.828 | 4.1601999999999315e-05 |
|
232
|
+
| hobbit | 0.6.1 | 40.391 | 6.76790000000015e-05 |
|
233
|
+
| brooklyn | 0.0.1 | 72.983 | 0.00012229050000000643 |
|
234
|
+
| nancy | 0.3.0 | 91.488 | 0.00015329779999998726 |
|
235
|
+
| scorched | 0.25 | 179.476 | 0.00030072970000003256 |
|
236
|
+
| sinatra | 1.4.7 | 191.033 | 0.00032009470000000435 |
|
237
|
+
| rails | 4.2.5.1 | 453.927 | 0.0007605999000000241 |
|
238
|
+
| camping | 2.1.532 | 574.146 | 0.0009620388000000196 |
|
239
|
+
| grape | 0.14.0 | 582.409 | 0.000975884299999979 |
|
240
|
+
| cuba | 3.5.0 | 763.772 | 0.001279777100000003 |
|
241
|
+
|
242
|
+
For more reports check the Benchmark repo out :)
|
238
243
|
|
239
244
|
## Roadmap
|
240
245
|
|
@@ -252,3 +257,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
252
257
|
|
253
258
|
Bug reports and pull requests are welcome on GitHub at https://github.com/adamluzsi/rack-app.rb This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
254
259
|
|
260
|
+
## License and Copyright
|
261
|
+
|
262
|
+
Rack::App is free software released under the [Apache License V2](https://opensource.org/licenses/Apache-2.0) License.
|
263
|
+
The logo was designed by Zsófia Gebauer. It is Copyright © 2015 Adam Luzsi. All Rights Reserved.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.24.0
|
data/lib/rack/app.rb
CHANGED
@@ -20,6 +20,64 @@ class Rack::App
|
|
20
20
|
|
21
21
|
class << self
|
22
22
|
|
23
|
+
def inherited(klass)
|
24
|
+
|
25
|
+
error.handlers.each do |ex_class, block|
|
26
|
+
klass.error(ex_class, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
klass.serializer(&serializer.logic)
|
30
|
+
middlewares.each { |builder_block| klass.middlewares(&builder_block) }
|
31
|
+
klass.headers.merge!(headers)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def serializer(&definition_how_to_serialize)
|
36
|
+
@serializer ||= Rack::App::Serializer.new
|
37
|
+
|
38
|
+
unless definition_how_to_serialize.nil?
|
39
|
+
@serializer.set_serialization_logic(definition_how_to_serialize)
|
40
|
+
end
|
41
|
+
|
42
|
+
return @serializer
|
43
|
+
end
|
44
|
+
|
45
|
+
def headers(new_headers=nil)
|
46
|
+
@headers ||= {}
|
47
|
+
@headers.merge!(new_headers) if new_headers.is_a?(Hash)
|
48
|
+
@headers
|
49
|
+
end
|
50
|
+
|
51
|
+
def middlewares(&block)
|
52
|
+
@middlewares ||= []
|
53
|
+
@middlewares << block unless block.nil?
|
54
|
+
@middlewares
|
55
|
+
end
|
56
|
+
|
57
|
+
alias middleware middlewares
|
58
|
+
|
59
|
+
def error(*exception_classes, &block)
|
60
|
+
@error_handler ||= Rack::App::ErrorHandler.new
|
61
|
+
unless block.nil?
|
62
|
+
@error_handler.register_handler(exception_classes, block)
|
63
|
+
end
|
64
|
+
|
65
|
+
return @error_handler
|
66
|
+
end
|
67
|
+
|
68
|
+
def namespace(request_path_namespace)
|
69
|
+
return unless block_given?
|
70
|
+
@namespaces ||= []
|
71
|
+
@namespaces.push(request_path_namespace)
|
72
|
+
yield
|
73
|
+
@namespaces.pop
|
74
|
+
nil
|
75
|
+
end
|
76
|
+
|
77
|
+
def router
|
78
|
+
@router ||= Rack::App::Router.new
|
79
|
+
end
|
80
|
+
|
23
81
|
def call(request_env)
|
24
82
|
Rack::App::RequestConfigurator.configure(request_env)
|
25
83
|
endpoint = router.fetch_endpoint(
|
@@ -75,23 +133,15 @@ class Rack::App
|
|
75
133
|
end
|
76
134
|
end
|
77
135
|
|
78
|
-
def error(*exception_classes, &block)
|
79
|
-
@error_handler ||= Rack::App::ErrorHandler.new
|
80
|
-
unless block.nil?
|
81
|
-
@error_handler.register_handler(exception_classes, block)
|
82
|
-
end
|
83
|
-
|
84
|
-
return @error_handler
|
85
|
-
end
|
86
|
-
|
87
|
-
def router
|
88
|
-
@router ||= Rack::App::Router.new
|
89
|
-
end
|
90
|
-
|
91
136
|
def add_route(request_method, request_path, &block)
|
92
137
|
|
93
138
|
request_path = ::Rack::App::Utils.join(@namespaces, request_path)
|
94
139
|
|
140
|
+
builder = Rack::Builder.new
|
141
|
+
middlewares.each do |builder_block|
|
142
|
+
builder_block.call(builder)
|
143
|
+
end
|
144
|
+
|
95
145
|
properties = {
|
96
146
|
:user_defined_logic => block,
|
97
147
|
:request_method => request_method,
|
@@ -101,7 +151,7 @@ class Rack::App
|
|
101
151
|
:error_handler => error,
|
102
152
|
:description => @last_description,
|
103
153
|
:serializer => serializer,
|
104
|
-
:middleware =>
|
154
|
+
:middleware => builder,
|
105
155
|
:app_class => self
|
106
156
|
}
|
107
157
|
|
@@ -133,37 +183,6 @@ class Rack::App
|
|
133
183
|
return nil
|
134
184
|
end
|
135
185
|
|
136
|
-
def serializer(&definition_how_to_serialize)
|
137
|
-
@serializer ||= Rack::App::Serializer.new
|
138
|
-
|
139
|
-
unless definition_how_to_serialize.nil?
|
140
|
-
@serializer.set_serialization_logic(definition_how_to_serialize)
|
141
|
-
end
|
142
|
-
|
143
|
-
return @serializer
|
144
|
-
end
|
145
|
-
|
146
|
-
def headers(new_headers=nil)
|
147
|
-
@headers ||= {}
|
148
|
-
@headers.merge!(new_headers) if new_headers.is_a?(Hash)
|
149
|
-
@headers
|
150
|
-
end
|
151
|
-
|
152
|
-
def namespace(request_path_namespace)
|
153
|
-
return unless block_given?
|
154
|
-
@namespaces ||= []
|
155
|
-
@namespaces.push(request_path_namespace)
|
156
|
-
yield
|
157
|
-
@namespaces.pop
|
158
|
-
nil
|
159
|
-
end
|
160
|
-
|
161
|
-
def middleware(&block)
|
162
|
-
@builder ||= Rack::Builder.new
|
163
|
-
block.call(@builder) unless block.nil?
|
164
|
-
@builder
|
165
|
-
end
|
166
|
-
|
167
186
|
end
|
168
187
|
|
169
188
|
def params
|
data/lib/rack/app/serializer.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
class Rack::App::Serializer
|
2
2
|
|
3
|
+
attr_reader :logic
|
4
|
+
|
3
5
|
def initialize
|
4
|
-
@
|
6
|
+
@logic = lambda { |o| o.to_s }
|
5
7
|
end
|
6
8
|
|
7
9
|
def set_serialization_logic(proc)
|
8
|
-
@
|
10
|
+
@logic = proc
|
9
11
|
end
|
10
12
|
|
11
13
|
def serialize(object)
|
12
|
-
@
|
14
|
+
@logic.call(object)
|
13
15
|
end
|
14
16
|
|
15
17
|
end
|
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.
|
4
|
+
version: 0.24.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-
|
12
|
+
date: 2016-02-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|