rack-app 5.12.0 → 6.0.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 +19 -13
- data/VERSION +1 -1
- data/lib/rack/app/block.rb +2 -0
- data/lib/rack/app/endpoint/builder.rb +13 -5
- data/lib/rack/app/endpoint/config.rb +17 -10
- data/lib/rack/app/endpoint/executor.rb +1 -2
- data/lib/rack/app/endpoint.rb +1 -1
- data/lib/rack/app/instance_methods/core.rb +4 -0
- data/lib/rack/app/singleton_methods/http_methods.rb +10 -10
- data/lib/rack/app/singleton_methods/mounting.rb +4 -29
- data/lib/rack/app/singleton_methods/route_handling.rb +6 -3
- data/lib/rack/app.rb +1 -0
- metadata +3 -3
- data/spike/tree.rb +0 -76
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 115ef984aee400271ed64f69eee96b2bc3896cb9
|
4
|
+
data.tar.gz: dcb1b5ee1fd8af7b107b6dc50d9089fd9410657e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a921f4cc74415fd8aef272fd97bdd3fd53e2066e42266ddddc98a9271cee6df6612d695fa6129055d7d216df533f596099cea13fa59a8c311380f3e31dfa68de
|
7
|
+
data.tar.gz: fe97b75e3b27041a03b34daa0650c40fc4719161d3d1d91e355000f6454762d50b431f1384eddad588f387c6991f69e59f4d49203df0a9428b048381ec0abe97
|
data/README.md
CHANGED
@@ -68,7 +68,7 @@ Yes, in fact it's already powering heroku hosted micro-services.
|
|
68
68
|
* syntax sugar for default header definitions
|
69
69
|
* namespaces for endpoint request path declarations so it can be dry and unified
|
70
70
|
* no Class method bloat, so you can enjoy pure ruby without any surprises
|
71
|
-
* App mounting so you can
|
71
|
+
* App mounting so you can create separated controllers for different task
|
72
72
|
* Streaming
|
73
73
|
* O(log(n)) lookup routing
|
74
74
|
* allows as many endpoint registration to you as you want, without impact on route lookup speed
|
@@ -76,7 +76,7 @@ Yes, in fact it's already powering heroku hosted micro-services.
|
|
76
76
|
* simple to use class level response serializer
|
77
77
|
* so you can choose what type of serialization you want without any enforced convention
|
78
78
|
* static file serving so you can mount even filesystem based endpoints too
|
79
|
-
* built in testing module so your app can easily written with BDD approach
|
79
|
+
* built in testing module so your app can be easily written with BDD approach
|
80
80
|
* made with performance in mind so your app don't lose time by your framework
|
81
81
|
* per endpoint middleware definitions
|
82
82
|
* you can define middleware stack before endpoints and it will only applied to them, similar like protected method workflow
|
@@ -266,7 +266,6 @@ the benchmarking was taken on the following hardware specification:
|
|
266
266
|
|
267
267
|
### Endpoint to be call type: static
|
268
268
|
|
269
|
-
|
270
269
|
#### number of declared endpoints: 100
|
271
270
|
|
272
271
|
| name | version | current / fastest | real |
|
@@ -274,21 +273,28 @@ the benchmarking was taken on the following hardware specification:
|
|
274
273
|
| rack-app | 4.0.0 | 1.0 | 2.2053215187043942e-05 |
|
275
274
|
| rack-app | 5.2.0 | 1.185 | 2.6140331494390213e-05 |
|
276
275
|
| rack-app | 5.0.0.rc3 | 1.387 | 3.0592694940592784e-05 |
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
276
|
+
| rack-app | 5.10.0 | 1.687 | 3.719768107671963e-05 |
|
277
|
+
| rack-app | 5.12.0 | 1.747 | 3.852106360719058e-05 |
|
278
|
+
| rack-app | 5.7.0 | 1.784 | 3.934149001724991e-05 |
|
279
|
+
| ramaze | 2012.12.08 | 2.237 | 4.932373271523216e-05 |
|
280
|
+
| hobbit | 0.6.1 | 3.111 | 6.860981349018188e-05 |
|
281
|
+
| brooklyn | 0.0.1 | 5.245 | 0.00011567194234917104 |
|
281
282
|
| plezi | 0.14.1 | 5.334 | 0.00011763589749898317 |
|
282
|
-
|
|
283
|
+
| plezi | 0.14.2 | 5.588 | 0.00012324020796222724 |
|
284
|
+
| nancy | 0.3.0 | 5.725 | 0.00012626088352407584 |
|
285
|
+
| nyny | 3.4.3 | 5.744 | 0.00012667404900032145 |
|
286
|
+
| roda | 2.20.0 | 9.662 | 0.00021307581296423227 |
|
283
287
|
| roda | 2.17.0 | 10.646 | 0.00023477471132838754 |
|
284
288
|
| scorched | 0.25 | 12.728 | 0.0002807019599946191 |
|
285
|
-
|
|
289
|
+
| scorched | 0.27 | 16.074 | 0.0003544879730325173 |
|
290
|
+
| sinatra | 1.4.7 | 19.857 | 0.00043791615583657487 |
|
286
291
|
| grape | 0.17.0 | 25.941 | 0.0005720832234016178 |
|
287
292
|
| rails | 5.0.0 | 33.234 | 0.0007329187002032537 |
|
288
|
-
| camping | 2.1.532 | 39.
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
293
|
+
| camping | 2.1.532 | 39.818 | 0.0008781073650072727 |
|
294
|
+
| grape | 0.18.0 | 41.857 | 0.000923075147962645 |
|
295
|
+
| rails | 5.0.0.1 | 47.286 | 0.0010428086559986802 |
|
296
|
+
| cuba | 3.8.0 | 55.397 | 0.0012216723478342246 |
|
297
|
+
| almost-sinatra | unknown | 58.728 | 0.0012951477793394547 |
|
292
298
|
|
293
299
|
For more reports check the Benchmark repo out :)
|
294
300
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
6.0.0
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rack/builder'
|
2
3
|
class Rack::App::Endpoint::Builder
|
3
|
-
|
4
4
|
def initialize(config)
|
5
5
|
@config = config
|
6
6
|
end
|
@@ -8,12 +8,21 @@ class Rack::App::Endpoint::Builder
|
|
8
8
|
def build
|
9
9
|
builder = Rack::Builder.new
|
10
10
|
apply_middleware_build_blocks(builder)
|
11
|
-
builder.run(
|
11
|
+
builder.run(app)
|
12
12
|
builder.to_app
|
13
13
|
end
|
14
14
|
|
15
15
|
protected
|
16
16
|
|
17
|
+
def app
|
18
|
+
case @config.type
|
19
|
+
when :endpoint
|
20
|
+
Rack::App::Endpoint::Executor.new(@config)
|
21
|
+
else
|
22
|
+
@config.callable
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
17
26
|
def apply_middleware_build_blocks(builder)
|
18
27
|
builder_blocks.each do |builder_block|
|
19
28
|
builder_block.call(builder)
|
@@ -32,7 +41,6 @@ class Rack::App::Endpoint::Builder
|
|
32
41
|
end
|
33
42
|
|
34
43
|
def builder_blocks
|
35
|
-
[@config.app_class.middlewares, @config.
|
44
|
+
[@config.app_class.middlewares, @config.endpoint_specific_middlewares].flatten
|
36
45
|
end
|
37
|
-
|
38
46
|
end
|
@@ -1,20 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
class Rack::App::Endpoint::Config
|
3
|
+
|
3
4
|
def to_hash
|
4
5
|
error_handler
|
5
|
-
|
6
|
+
endpoint_specific_middlewares
|
6
7
|
request_path
|
7
8
|
request_methods
|
8
9
|
defined_request_path
|
9
10
|
@raw
|
10
11
|
end
|
11
12
|
|
12
|
-
def
|
13
|
-
@raw[:
|
13
|
+
def callable
|
14
|
+
@raw[:callable]
|
15
|
+
end
|
16
|
+
|
17
|
+
def type
|
18
|
+
case callable
|
19
|
+
when ::Rack::App::Block
|
20
|
+
:endpoint
|
21
|
+
else
|
22
|
+
:application
|
23
|
+
end
|
14
24
|
end
|
15
25
|
|
16
|
-
def
|
17
|
-
@raw[:
|
26
|
+
def payload_builder
|
27
|
+
@raw[:payload].parser_builder
|
18
28
|
end
|
19
29
|
|
20
30
|
def app_class
|
@@ -41,13 +51,10 @@ class Rack::App::Endpoint::Config
|
|
41
51
|
@raw[:error_handler] ||= Rack::App::ErrorHandler.new
|
42
52
|
end
|
43
53
|
|
44
|
-
def
|
45
|
-
@raw[:
|
54
|
+
def endpoint_specific_middlewares
|
55
|
+
@raw[:endpoint_specific_middlewares] ||= []
|
46
56
|
end
|
47
57
|
|
48
|
-
def endpoint_method_name
|
49
|
-
@raw[:method_name] ||= register_method_to_app_class
|
50
|
-
end
|
51
58
|
|
52
59
|
def request_methods
|
53
60
|
case @raw[:request_methods] || raise('missing config: request_methods')
|
@@ -2,7 +2,6 @@ class Rack::App::Endpoint::Executor
|
|
2
2
|
|
3
3
|
def initialize(endpoint_properties)
|
4
4
|
@endpoint_properties = endpoint_properties
|
5
|
-
@endpoint_properties.endpoint_method_name
|
6
5
|
end
|
7
6
|
|
8
7
|
def call(env)
|
@@ -35,7 +34,7 @@ class Rack::App::Endpoint::Executor
|
|
35
34
|
|
36
35
|
def evaluate_value(request_handler)
|
37
36
|
@endpoint_properties.error_handler.execute_with_error_handling_for(request_handler) do
|
38
|
-
request_handler.
|
37
|
+
request_handler.instance_exec(&@endpoint_properties.callable)
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
data/lib/rack/app/endpoint.rb
CHANGED
@@ -3,43 +3,43 @@ module Rack::App::SingletonMethods::HttpMethods
|
|
3
3
|
protected
|
4
4
|
|
5
5
|
def get(path = '/', &block)
|
6
|
-
add_route(::Rack::App::Constants::HTTP::METHOD::GET, path, &block)
|
6
|
+
add_route(::Rack::App::Constants::HTTP::METHOD::GET, path, Rack::App::Block.new(&block))
|
7
7
|
end
|
8
8
|
|
9
9
|
def post(path = '/', &block)
|
10
|
-
add_route(::Rack::App::Constants::HTTP::METHOD::POST, path, &block)
|
10
|
+
add_route(::Rack::App::Constants::HTTP::METHOD::POST, path, Rack::App::Block.new(&block))
|
11
11
|
end
|
12
12
|
|
13
13
|
def put(path = '/', &block)
|
14
|
-
add_route(::Rack::App::Constants::HTTP::METHOD::PUT, path, &block)
|
14
|
+
add_route(::Rack::App::Constants::HTTP::METHOD::PUT, path, Rack::App::Block.new(&block))
|
15
15
|
end
|
16
16
|
|
17
17
|
def delete(path = '/', &block)
|
18
|
-
add_route(::Rack::App::Constants::HTTP::METHOD::DELETE, path, &block)
|
18
|
+
add_route(::Rack::App::Constants::HTTP::METHOD::DELETE, path, Rack::App::Block.new(&block))
|
19
19
|
end
|
20
20
|
|
21
21
|
def head(path = '/', &block)
|
22
|
-
add_route(::Rack::App::Constants::HTTP::METHOD::HEAD, path, &block)
|
22
|
+
add_route(::Rack::App::Constants::HTTP::METHOD::HEAD, path, Rack::App::Block.new(&block))
|
23
23
|
end
|
24
24
|
|
25
25
|
def options(path = '/', &block)
|
26
|
-
add_route(::Rack::App::Constants::HTTP::METHOD::OPTIONS, path, &block)
|
26
|
+
add_route(::Rack::App::Constants::HTTP::METHOD::OPTIONS, path, Rack::App::Block.new(&block))
|
27
27
|
end
|
28
28
|
|
29
29
|
def patch(path = '/', &block)
|
30
|
-
add_route(::Rack::App::Constants::HTTP::METHOD::PATCH, path, &block)
|
30
|
+
add_route(::Rack::App::Constants::HTTP::METHOD::PATCH, path, Rack::App::Block.new(&block))
|
31
31
|
end
|
32
32
|
|
33
33
|
def link(path = '/', &block)
|
34
|
-
add_route(::Rack::App::Constants::HTTP::METHOD::LINK, path, &block)
|
34
|
+
add_route(::Rack::App::Constants::HTTP::METHOD::LINK, path, Rack::App::Block.new(&block))
|
35
35
|
end
|
36
36
|
|
37
37
|
def unlink(path = '/', &block)
|
38
|
-
add_route(::Rack::App::Constants::HTTP::METHOD::UNLINK, path, &block)
|
38
|
+
add_route(::Rack::App::Constants::HTTP::METHOD::UNLINK, path, Rack::App::Block.new(&block))
|
39
39
|
end
|
40
40
|
|
41
41
|
def trace(path = '/', &block)
|
42
|
-
add_route(::Rack::App::Constants::HTTP::METHOD::TRACE, path, &block)
|
42
|
+
add_route(::Rack::App::Constants::HTTP::METHOD::TRACE, path, Rack::App::Block.new(&block))
|
43
43
|
end
|
44
44
|
|
45
45
|
def alias_endpoint(new_request_path, original_request_path)
|
@@ -41,41 +41,16 @@ module Rack::App::SingletonMethods::Mounting
|
|
41
41
|
nil
|
42
42
|
end
|
43
43
|
|
44
|
-
alias create_endpoints_for_files_in mount_directory
|
45
|
-
Rack::App::Utils.deprecate(self,:create_endpoints_for_files_in, :mount_directory, 2016,9)
|
46
|
-
|
47
44
|
def serve_files_from(file_path, options={})
|
48
45
|
file_server = Rack::App::FileServer.new(Rack::App::Utils.expand_path(file_path))
|
49
|
-
request_path = Rack::App::Utils.join(
|
50
|
-
|
51
|
-
endpoint = Rack::App::Endpoint.new(
|
52
|
-
route_registration_properties.merge(
|
53
|
-
:request_methods => [
|
54
|
-
Rack::App::Constants::HTTP::METHOD::GET,
|
55
|
-
Rack::App::Constants::HTTP::METHOD::OPTIONS
|
56
|
-
],
|
57
|
-
:request_path => request_path,
|
58
|
-
:application => file_server
|
59
|
-
)
|
60
|
-
)
|
61
|
-
|
62
|
-
router.register_endpoint!(endpoint)
|
63
|
-
route_registration_properties.clear
|
46
|
+
request_path = Rack::App::Utils.join(options[:to], Rack::App::Constants::PATH::MOUNT_POINT)
|
47
|
+
add_route(::Rack::App::Constants::HTTP::METHOD::ANY, request_path, file_server)
|
64
48
|
nil
|
65
49
|
end
|
66
50
|
|
67
51
|
def mount_rack_interface_compatible_application(rack_based_app, options={})
|
68
|
-
|
69
|
-
|
70
|
-
:request_path => Rack::App::Utils.join(
|
71
|
-
@namespaces,
|
72
|
-
options[:to],
|
73
|
-
Rack::App::Constants::PATH::APPLICATION
|
74
|
-
),
|
75
|
-
:application => rack_based_app
|
76
|
-
)
|
77
|
-
|
78
|
-
router.register_endpoint!(Rack::App::Endpoint.new(properties))
|
52
|
+
request_path = Rack::App::Utils.join(options[:to],Rack::App::Constants::PATH::APPLICATION)
|
53
|
+
add_route(::Rack::App::Constants::HTTP::METHOD::ANY, request_path, rack_based_app)
|
79
54
|
end
|
80
55
|
|
81
56
|
end
|
@@ -20,17 +20,17 @@ module Rack::App::SingletonMethods::RouteHandling
|
|
20
20
|
|
21
21
|
alias desc description
|
22
22
|
|
23
|
-
def add_route(request_method, request_path,
|
23
|
+
def add_route(request_method, request_path, callable)
|
24
24
|
|
25
25
|
router.register_endpoint!(
|
26
26
|
Rack::App::Endpoint.new({
|
27
27
|
:app_class => self,
|
28
|
+
:callable => callable,
|
28
29
|
:payload => payload,
|
29
30
|
:error_handler => error,
|
30
|
-
:user_defined_logic => block,
|
31
31
|
:request_methods => [request_method],
|
32
32
|
:route => route_registration_properties.dup,
|
33
|
-
:
|
33
|
+
:endpoint_specific_middlewares => next_endpoint_middlewares.dup,
|
34
34
|
:request_path => ::Rack::App::Utils.join(@namespaces, request_path)
|
35
35
|
})
|
36
36
|
)
|
@@ -41,6 +41,9 @@ module Rack::App::SingletonMethods::RouteHandling
|
|
41
41
|
|
42
42
|
end
|
43
43
|
|
44
|
+
def add_app_to_route(app, request_path)
|
45
|
+
end
|
46
|
+
|
44
47
|
def namespace(request_path_namespace)
|
45
48
|
return unless block_given?
|
46
49
|
@namespaces ||= []
|
data/lib/rack/app.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02
|
11
|
+
date: 2017-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- dev/console
|
94
94
|
- dev/rack-app
|
95
95
|
- lib/rack/app.rb
|
96
|
+
- lib/rack/app/block.rb
|
96
97
|
- lib/rack/app/bundled_extensions.rb
|
97
98
|
- lib/rack/app/bundled_extensions/logger.rb
|
98
99
|
- lib/rack/app/bundled_extensions/payload.rb
|
@@ -200,7 +201,6 @@ files:
|
|
200
201
|
- spike/method_vs_instance_exec.rb
|
201
202
|
- spike/return_vs_throw.rb
|
202
203
|
- spike/slice_vs_sub.rb
|
203
|
-
- spike/tree.rb
|
204
204
|
- spike/validator_with_minitest.rb
|
205
205
|
- spike/xml.rb
|
206
206
|
- src/Net__HTTP Cheat Sheet.pdf
|
data/spike/tree.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
rack_api_lib_folder = File.join(File.dirname(__FILE__), '..', 'lib')
|
5
|
-
$LOAD_PATH.unshift(rack_api_lib_folder)
|
6
|
-
require 'rack/app'
|
7
|
-
require 'pp'
|
8
|
-
|
9
|
-
tree = Rack::App::Router::Tree.new
|
10
|
-
|
11
|
-
APP = Class.new(Rack::App)
|
12
|
-
|
13
|
-
payload = Rack::App::Payload::Builder.new
|
14
|
-
|
15
|
-
payload.parser_builder do
|
16
|
-
accept :json
|
17
|
-
end
|
18
|
-
|
19
|
-
serializer = Rack::App::Serializer::FormatsBuilder.new
|
20
|
-
serializer.instance_exec do
|
21
|
-
on '.json', 'application/json' do |obj|
|
22
|
-
JSON.dump(obj)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
endpoint = Rack::App::Endpoint.new(
|
27
|
-
:route => {},
|
28
|
-
:app_class => APP,
|
29
|
-
:request_methods => ["GET"],
|
30
|
-
:request_path => '/hello/world/:id',
|
31
|
-
:middleware_builders_blocks => [],
|
32
|
-
:user_defined_logic => proc{ "hy" },
|
33
|
-
:serializer_builder => serializer,
|
34
|
-
:payload => payload,
|
35
|
-
:error_handler => Rack::App::ErrorHandler.new,
|
36
|
-
)
|
37
|
-
|
38
|
-
|
39
|
-
properties = {
|
40
|
-
:request_methods => ::Rack::App::Constants::HTTP::METHODS,
|
41
|
-
:request_path => Rack::App::Utils.join("hello", ::Rack::App::Constants::RACK_BASED_APPLICATION),
|
42
|
-
:application => proc{|env| Rack::Response.new.finish }
|
43
|
-
}
|
44
|
-
|
45
|
-
tree.add(Rack::App::Endpoint.new(properties))
|
46
|
-
|
47
|
-
endpoint = Rack::App::Endpoint.new(
|
48
|
-
:route => {},
|
49
|
-
:app_class => APP,
|
50
|
-
:request_methods => ["GET"],
|
51
|
-
:request_path => '/hello/world/:id',
|
52
|
-
:middleware_builders_blocks => [],
|
53
|
-
:user_defined_logic => proc{ "hy" },
|
54
|
-
:serializer_builder => serializer,
|
55
|
-
:payload => payload,
|
56
|
-
:error_handler => Rack::App::ErrorHandler.new,
|
57
|
-
)
|
58
|
-
|
59
|
-
tree.add(endpoint)
|
60
|
-
pp tree
|
61
|
-
|
62
|
-
require 'rack'
|
63
|
-
puts
|
64
|
-
|
65
|
-
[
|
66
|
-
"/hello/world/123.json",
|
67
|
-
"/hello/world/123",
|
68
|
-
"/hello/world",
|
69
|
-
].each do |path_info|
|
70
|
-
env = Rack::MockRequest.env_for(path_info, :method => 'GET')
|
71
|
-
resp = tree.call(env)
|
72
|
-
|
73
|
-
puts(path_info)
|
74
|
-
p resp.is_a?(Array) && resp.length == 3
|
75
|
-
puts
|
76
|
-
end
|