rack-app 0.22.0 → 0.23.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 +55 -14
- data/VERSION +1 -1
- data/lib/rack/app.rb +8 -0
- data/lib/rack/app/endpoint.rb +13 -4
- data/lib/rack/app/endpoint/not_found.rb +0 -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: fa7ed787ed29cd062ef3cbc6f721693f4a1d70df
|
4
|
+
data.tar.gz: e79de1870917b30fe6a4f940c16775deed6a49ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 030aa3836cb585f3a3c0d006efdae86646efe531fa48c97418f93dae495604fd8526cf7afdeb05a8adc6dd69b9349f5e1d25a31c4265f41968c3536cda00bf63
|
7
|
+
data.tar.gz: 58fd6808e3716ae0de6d4c90edd2ac61edfa353013502499ef1027b775c5b806111f481e7d80fa37dfd23ded75ba32f8457555d74eee072ff985fc11bde9231d
|
data/README.md
CHANGED
@@ -45,6 +45,41 @@ Or install it yourself as:
|
|
45
45
|
|
46
46
|
Yes, in fact it's already powering heroku hosted micro-services.
|
47
47
|
|
48
|
+
## Principles
|
49
|
+
|
50
|
+
* Keep It Simple
|
51
|
+
* No Code bloat
|
52
|
+
* No on run time processing, or keep at the bare minimum
|
53
|
+
* Fully BDD (Behaviour Driven Design)
|
54
|
+
* build in test module to ease the development with easy to use tests
|
55
|
+
* Easy to Learn
|
56
|
+
* rack-app use well known and easy to understand conventions, such as sinatra like DSL
|
57
|
+
* Principle Of Least Surprise
|
58
|
+
* Modular design
|
59
|
+
* Only dependency is rack, nothing more
|
60
|
+
* Open development
|
61
|
+
* Try to create Examples for every feature so even the "sketch to learn new" types can feel in comfort
|
62
|
+
|
63
|
+
## Features
|
64
|
+
|
65
|
+
* easy to understand syntax
|
66
|
+
* module method level endpoint definition inspirited heavily by the Sinatra DSL
|
67
|
+
* unified error handling
|
68
|
+
* syntax sugar for default header definitions
|
69
|
+
* namespaces for endpoint request path declarations so it can be dry and unified
|
70
|
+
* no Class method bloat, so you can enjoy pure ruby without any surprises
|
71
|
+
* App mounting so you can crete separated controllers for different task
|
72
|
+
* Null time look up routing
|
73
|
+
* allows as many endpoint registration to you as you want, without impact on route look up speed
|
74
|
+
* only basic sets for instance method lvl for the must need tools, such as params, payload
|
75
|
+
* simple to use class level response serializer
|
76
|
+
* so you can choose what type of serialization you want without any enforced convention
|
77
|
+
* static file serving so you can mount even filesystem based endpoints too
|
78
|
+
* built in testing module so your app can easily written with BDD approach
|
79
|
+
* made with performance in mind so your app don't lose time by your framework
|
80
|
+
* per endpoint middleware definitions
|
81
|
+
* you can define middleware stack before endpoints and it will only applied to them, similar like protected method workflow
|
82
|
+
|
48
83
|
## Usage
|
49
84
|
|
50
85
|
config.ru
|
@@ -180,20 +215,26 @@ end
|
|
180
215
|
|
181
216
|
## [Benchmarking](https://github.com/adamluzsi/rack-app.rb-benchmark)
|
182
217
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
218
|
+
the benchmarking was taken on the following hardware specification:
|
219
|
+
* Processor: 2,7 GHz Intel Core i5
|
220
|
+
* Memory: 16 GB 1867 MHz DDR3
|
221
|
+
* Ruby: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin15.0]
|
222
|
+
* Endpoint declaration count: 1000
|
223
|
+
|
224
|
+
| name | version | current / fastest | user | system | total | real |
|
225
|
+
| ---------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
|
226
|
+
| rack | 1.6.4 | 1.0 | 4.4999999999994597e-10 | 4.999999999999855e-11 | 5.000000000001581e-10 | 4.669824999999623e-10 |
|
227
|
+
| rack-app | 0.23.0 | 5.64 | 2.6249999999995462e-09 | 5.0000000000003155e-11 | 2.674999999999656e-09 | 2.6337825000000033e-09 |
|
228
|
+
| ramaze | 2012.12.08 | 10.761 | 4.7250000000004294e-09 | 3.249999999997837e-10 | 5.0499999999999815e-09 | 5.025382500000196e-09 |
|
229
|
+
| brooklyn | 0.0.1 | 135.196 | 6.202499999997365e-08 | 2.5000000000010383e-10 | 6.227499999994257e-08 | 6.31342025000291e-08 |
|
230
|
+
| nancy | 0.3.0 | 141.491 | 6.44500000000412e-08 | 4.0000000000002173e-10 | 6.485000000002128e-08 | 6.607404000000881e-08 |
|
231
|
+
| rails | 4.2.5.1 | 149.063 | 6.475000000004323e-08 | 2.54999999999825e-09 | 6.729999999999027e-08 | 6.960978250001378e-08 |
|
232
|
+
| hobbit | 0.6.1 | 152.009 | 6.86499999999909e-08 | 5.50000000000627e-10 | 6.920000000002929e-08 | 7.09855800000375e-08 |
|
233
|
+
| scorched | 0.25 | 206.02 | 9.227499999997586e-08 | 6.249999999997911e-10 | 9.289999999997338e-08 | 9.620763750005751e-08 |
|
234
|
+
| sinatra | 1.4.7 | 252.893 | 1.1582499999996941e-07 | 9.000000000006287e-10 | 1.167249999999214e-07 | 1.1809659249996387e-07 |
|
235
|
+
| grape | 0.14.0 | 999.893 | 4.5052499999980065e-07 | 4.900000000001301e-09 | 4.554249999998522e-07 | 4.66932680000025e-07 |
|
236
|
+
| camping | 2.1.532 | 2246.199 | 1.0080499999997654e-06 | 1.4049999999999699e-08 | 1.0220999999995006e-06 | 1.0489356725004438e-06 |
|
237
|
+
| cuba | 3.5.0 | 2951.837 | 1.3101249999997173e-06 | 1.302499999999637e-08 | 1.3231499999997228e-06 | 1.3784562299989904e-06 |
|
197
238
|
|
198
239
|
## Roadmap
|
199
240
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.23.0
|
data/lib/rack/app.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rack'
|
2
|
+
require 'rack/builder'
|
2
3
|
require 'rack/request'
|
3
4
|
require 'rack/response'
|
4
5
|
class Rack::App
|
@@ -100,6 +101,7 @@ class Rack::App
|
|
100
101
|
:error_handler => error,
|
101
102
|
:description => @last_description,
|
102
103
|
:serializer => serializer,
|
104
|
+
:middleware => middleware,
|
103
105
|
:app_class => self
|
104
106
|
}
|
105
107
|
|
@@ -156,6 +158,12 @@ class Rack::App
|
|
156
158
|
nil
|
157
159
|
end
|
158
160
|
|
161
|
+
def middleware(&block)
|
162
|
+
@builder ||= Rack::Builder.new
|
163
|
+
block.call(@builder) unless block.nil?
|
164
|
+
@builder
|
165
|
+
end
|
166
|
+
|
159
167
|
end
|
160
168
|
|
161
169
|
def params
|
data/lib/rack/app/endpoint.rb
CHANGED
@@ -7,16 +7,25 @@ class Rack::App::Endpoint
|
|
7
7
|
def initialize(properties)
|
8
8
|
@properties = properties
|
9
9
|
|
10
|
-
@error_handler = properties[:error_handler]
|
11
|
-
@serializer = properties[:serializer]
|
12
10
|
@api_class = properties[:app_class]
|
13
|
-
@
|
11
|
+
@error_handler = properties[:error_handler] || Rack::App::ErrorHandler.new
|
12
|
+
@serializer = properties[:serializer] || Rack::App::Serializer.new
|
13
|
+
@headers = properties[:default_headers] || {}
|
14
|
+
|
15
|
+
@middleware = (properties[:middleware] || Rack::Builder.new).dup
|
16
|
+
@middleware.run(lambda { |env| self.execute(env) })
|
14
17
|
|
15
18
|
@path_params_matcher = {}
|
16
19
|
@endpoint_method_name = register_method_to_app_class(properties[:user_defined_logic])
|
20
|
+
|
21
|
+
@app = @middleware.to_app
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(env)
|
25
|
+
@app.call(env)
|
17
26
|
end
|
18
27
|
|
19
|
-
def
|
28
|
+
def execute(request_env)
|
20
29
|
|
21
30
|
request = Rack::Request.new(request_env)
|
22
31
|
response = Rack::Response.new
|
@@ -4,12 +4,9 @@ not_found_properties = {
|
|
4
4
|
response.status= 404
|
5
5
|
return '404 Not Found'
|
6
6
|
},
|
7
|
-
:default_headers => {},
|
8
7
|
:request_method => 'GET',
|
9
|
-
:error_handler => Rack::App::ErrorHandler.new,
|
10
8
|
:request_path => '\404',
|
11
9
|
:description => 'page not found',
|
12
|
-
:serializer => Rack::App::Serializer.new,
|
13
10
|
:app_class => app_class
|
14
11
|
}
|
15
12
|
|
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.23.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-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|