rack-app 5.2.0 → 5.3.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 +4 -4
- data/CONTRIBUTORS.md +4 -0
- data/README.md +31 -23
- data/VERSION +1 -1
- data/lib/rack/app/endpoint.rb +17 -33
- data/lib/rack/app/endpoint/builder.rb +39 -0
- data/lib/rack/app/endpoint/{properties.rb → config.rb} +19 -3
- data/lib/rack/app/file_server.rb +1 -1
- data/lib/rack/app/router.rb +14 -24
- data/lib/rack/app/router/base.rb +4 -13
- data/lib/rack/app/router/dynamic.rb +6 -3
- data/lib/rack/app/router/static.rb +4 -3
- data/lib/rack/app/serializer.rb +2 -6
- data/lib/rack/app/singleton_methods/http_methods.rb +4 -6
- data/lib/rack/app/singleton_methods/middleware.rb +12 -4
- data/lib/rack/app/singleton_methods/mounting.rb +40 -7
- data/lib/rack/app/singleton_methods/params_validator.rb +1 -1
- data/lib/rack/app/singleton_methods/route_handling.rb +14 -16
- data/lib/rack/app/singleton_methods/settings.rb +1 -5
- data/lib/rack/app/utils.rb +23 -0
- data/spec_files.txt +1 -1
- data/spike/method_vs_hash.rb +78 -0
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 56ff6cb0ae7c0fe3de38e1e76bd6003eb11d0455
|
|
4
|
+
data.tar.gz: b2c795ba758dfcd5f9206e65d6baafc33ee4eedc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 750db656ebbc3f12667decd66bbdeed4e1ac1c5b7c3a0e6ad98dead9e963e5a54396f98b9c200767c3e2e0e774bdeb9dd5b8a8fe5734deee6cf5d20a1a537a90
|
|
7
|
+
data.tar.gz: 5002bd81d4ff647d98db7e8d5287a1902f0dc68a5b6656783f54e892ccc8960d808e9f667061761a59c85fbb60a161a8096e5012d5720727915400857896b744
|
data/CONTRIBUTORS.md
CHANGED
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# [Rack::App](http://rack-app.com/) [![Build Status][travis-image]][travis-link]
|
|
1
|
+
# [Rack::App](http://www.rack-app.com/) [![Build Status][travis-image]][travis-link]
|
|
2
2
|
|
|
3
3
|
[travis-image]: https://travis-ci.org/rack-app/rack-app.svg?branch=master
|
|
4
|
-
[travis-link]:
|
|
4
|
+
[travis-link]: https://travis-ci.org/rack-app/rack-app
|
|
5
5
|
[travis-home]: http://travis-ci.org/
|
|
6
6
|
|
|
7
7
|
Your next favourite rack based micro framework that is totally addition free!
|
|
@@ -13,7 +13,7 @@ while able to write pure rack apps,
|
|
|
13
13
|
that will do nothing more than what you defined.
|
|
14
14
|
|
|
15
15
|
If you want see fancy magic, you are in a bad place buddy!
|
|
16
|
-
This
|
|
16
|
+
This also implies that the framework does not include extensions like ActiveSupport that monkey patch the whole world.
|
|
17
17
|
|
|
18
18
|
Routing can handle any amount of endpoints that can fit in the memory,
|
|
19
19
|
so if you that crazy to use more than 10k endpoint,
|
|
@@ -79,7 +79,7 @@ Yes, in fact it's already powering heroku hosted micro-services.
|
|
|
79
79
|
* per endpoint middleware definitions
|
|
80
80
|
* you can define middleware stack before endpoints and it will only applied to them, similar like protected method workflow
|
|
81
81
|
* File Upload and file download in a efficient and elegant way with minimal memory consuming
|
|
82
|
-
* note that this is not only memory friendly way pure rack solution, but also 2x faster than the
|
|
82
|
+
* note that this is not only memory friendly way pure rack solution, but also 2x faster than the usually solution which includes buffering in memory
|
|
83
83
|
* params validation with ease
|
|
84
84
|
|
|
85
85
|
## [Contributors](CONTRIBUTORS.md)
|
|
@@ -238,31 +238,39 @@ end
|
|
|
238
238
|
|
|
239
239
|
## [Benchmarking](https://github.com/rack-app/rack-app-benchmark)
|
|
240
240
|
|
|
241
|
+
This is a repo that used for measure Rack::App project speed in order keep an eye on the performance in every release.
|
|
242
|
+
|
|
241
243
|
the benchmarking was taken on the following hardware specification:
|
|
242
244
|
* Processor: 2,7 GHz Intel Core i5
|
|
243
245
|
* Memory: 16 GB 1867 MHz DDR3
|
|
244
|
-
* Ruby: ruby 2.
|
|
246
|
+
* Ruby: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
### Endpoint to be call type: static
|
|
245
250
|
|
|
246
|
-
|
|
251
|
+
|
|
252
|
+
#### number of declared endpoints: 100
|
|
247
253
|
|
|
248
254
|
| name | version | current / fastest | real |
|
|
249
255
|
| ---------------------- | ---------------------- | ---------------------- | ---------------------- |
|
|
250
|
-
| rack
|
|
251
|
-
| rack-app |
|
|
252
|
-
| rack-app |
|
|
253
|
-
|
|
|
254
|
-
|
|
|
255
|
-
|
|
|
256
|
-
|
|
|
257
|
-
|
|
|
258
|
-
|
|
|
259
|
-
|
|
|
260
|
-
| scorched | 0.25 |
|
|
261
|
-
| sinatra | 1.4.7 |
|
|
262
|
-
|
|
|
263
|
-
|
|
|
264
|
-
|
|
|
265
|
-
| cuba | 3.
|
|
256
|
+
| rack-app | 4.0.0 | 1.0 | 2.2053215187043942e-05 |
|
|
257
|
+
| rack-app | 5.2.0 | 1.185 | 2.6140331494390213e-05 |
|
|
258
|
+
| rack-app | 5.0.0.rc3 | 1.387 | 3.0592694940592784e-05 |
|
|
259
|
+
| ramaze | 2012.12.08 | 1.468 | 3.236885466806858e-05 |
|
|
260
|
+
| hobbit | 0.6.1 | 2.996 | 6.607205038890137e-05 |
|
|
261
|
+
| brooklyn | 0.0.1 | 5.243 | 0.00011562206838279088 |
|
|
262
|
+
| nyny | 3.4.3 | 5.272 | 0.00011626420279498706 |
|
|
263
|
+
| plezi | 0.14.1 | 5.334 | 0.00011763589749898317 |
|
|
264
|
+
| nancy | 0.3.0 | 5.649 | 0.00012458588462322884 |
|
|
265
|
+
| roda | 2.17.0 | 10.646 | 0.00023477471132838754 |
|
|
266
|
+
| scorched | 0.25 | 12.728 | 0.0002807019599946191 |
|
|
267
|
+
| sinatra | 1.4.7 | 21.169 | 0.0004668393424013356 |
|
|
268
|
+
| grape | 0.17.0 | 25.941 | 0.0005720832234016178 |
|
|
269
|
+
| rails | 5.0.0 | 33.234 | 0.0007329187002032537 |
|
|
270
|
+
| camping | 2.1.532 | 39.699 | 0.0008754866444039887 |
|
|
271
|
+
| cuba | 3.8.0 | 54.196 | 0.001195195165998367 |
|
|
272
|
+
| almost-sinatra | unknown | 58.613 | 0.0012926107780076503 |
|
|
273
|
+
|
|
266
274
|
|
|
267
275
|
For more reports check the Benchmark repo out :)
|
|
268
276
|
|
|
@@ -280,7 +288,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
280
288
|
|
|
281
289
|
## Contributing
|
|
282
290
|
|
|
283
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
291
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rack-app/rack-app 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.
|
|
284
292
|
|
|
285
293
|
## License and Copyright
|
|
286
294
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
5.
|
|
1
|
+
5.3.0
|
data/lib/rack/app/endpoint.rb
CHANGED
|
@@ -1,49 +1,33 @@
|
|
|
1
|
-
require "rack/builder"
|
|
2
1
|
class Rack::App::Endpoint
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
require "forwardable"
|
|
4
|
+
extend Forwardable
|
|
5
|
+
def_delegators :@config, :request_method, :request_path, :description
|
|
6
|
+
|
|
7
|
+
require "rack/app/endpoint/config"
|
|
8
|
+
require "rack/app/endpoint/builder"
|
|
4
9
|
require "rack/app/endpoint/executor"
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
@properties.to_hash
|
|
8
|
-
end
|
|
11
|
+
attr_reader :config
|
|
9
12
|
|
|
10
13
|
def initialize(properties)
|
|
11
|
-
@
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def call(env)
|
|
15
|
-
to_app.call(env)
|
|
14
|
+
@config = Rack::App::Endpoint::Config.new(properties)
|
|
16
15
|
end
|
|
17
16
|
|
|
18
|
-
def
|
|
19
|
-
|
|
20
|
-
apply_middleware_build_blocks(builder)
|
|
21
|
-
@properties.endpoint_method_name
|
|
22
|
-
builder.run(Rack::App::Endpoint::Executor.new(@properties))
|
|
23
|
-
builder.to_app
|
|
17
|
+
def fork(differences_in_properties)
|
|
18
|
+
self.class.new(self.properties.merge(differences_in_properties))
|
|
24
19
|
end
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def apply_middleware_build_blocks(builder)
|
|
29
|
-
builder_blocks.each do |builder_block|
|
|
30
|
-
builder_block.call(builder)
|
|
31
|
-
end
|
|
32
|
-
builder.use(Rack::App::Middlewares::Configuration, @properties.to_hash)
|
|
33
|
-
apply_hook_middlewares(builder)
|
|
21
|
+
def properties
|
|
22
|
+
@config.to_hash
|
|
34
23
|
end
|
|
35
24
|
|
|
36
|
-
def
|
|
37
|
-
|
|
38
|
-
builder.use(Rack::App::Middlewares::Hooks::Before, before_block)
|
|
39
|
-
end
|
|
40
|
-
@properties.app_class.after.each do |after_block|
|
|
41
|
-
builder.use(Rack::App::Middlewares::Hooks::After, after_block)
|
|
42
|
-
end
|
|
25
|
+
def call(env)
|
|
26
|
+
to_app.call(env)
|
|
43
27
|
end
|
|
44
28
|
|
|
45
|
-
def
|
|
46
|
-
@
|
|
29
|
+
def to_app
|
|
30
|
+
@config.application || self.class::Builder.new(@config).build
|
|
47
31
|
end
|
|
48
32
|
|
|
49
33
|
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require "rack/builder"
|
|
2
|
+
class Rack::App::Endpoint::Builder
|
|
3
|
+
|
|
4
|
+
def initialize(config)
|
|
5
|
+
@config = config
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def build
|
|
9
|
+
builder = Rack::Builder.new
|
|
10
|
+
apply_middleware_build_blocks(builder)
|
|
11
|
+
@config.endpoint_method_name
|
|
12
|
+
builder.run(Rack::App::Endpoint::Executor.new(@config))
|
|
13
|
+
builder.to_app
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
protected
|
|
17
|
+
|
|
18
|
+
def apply_middleware_build_blocks(builder)
|
|
19
|
+
builder_blocks.each do |builder_block|
|
|
20
|
+
builder_block.call(builder)
|
|
21
|
+
end
|
|
22
|
+
builder.use(Rack::App::Middlewares::Configuration, @config.to_hash)
|
|
23
|
+
apply_hook_middlewares(builder)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def apply_hook_middlewares(builder)
|
|
27
|
+
@config.app_class.before.each do |before_block|
|
|
28
|
+
builder.use(Rack::App::Middlewares::Hooks::Before, before_block)
|
|
29
|
+
end
|
|
30
|
+
@config.app_class.after.each do |after_block|
|
|
31
|
+
builder.use(Rack::App::Middlewares::Hooks::After, after_block)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def builder_blocks
|
|
36
|
+
@config.app_class.middlewares + @config.middleware_builders_blocks
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
class Rack::App::Endpoint::
|
|
1
|
+
class Rack::App::Endpoint::Config
|
|
2
2
|
|
|
3
3
|
def to_hash
|
|
4
|
-
app_class
|
|
5
4
|
serializer
|
|
6
5
|
error_handler
|
|
7
6
|
middleware_builders_blocks
|
|
8
|
-
|
|
7
|
+
request_path
|
|
8
|
+
request_method
|
|
9
9
|
return @raw
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
def application
|
|
13
|
+
@raw[:application]
|
|
14
|
+
end
|
|
15
|
+
|
|
12
16
|
def app_class
|
|
13
17
|
@raw[:app_class] || raise('missing app class')
|
|
14
18
|
end
|
|
@@ -29,6 +33,18 @@ class Rack::App::Endpoint::Properties
|
|
|
29
33
|
@raw[:method_name] ||= register_method_to_app_class
|
|
30
34
|
end
|
|
31
35
|
|
|
36
|
+
def request_method
|
|
37
|
+
(@raw[:request_method] || raise('missing request_method!')).to_s.upcase
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def request_path
|
|
41
|
+
Rack::App::Utils.normalize_path(@raw[:request_path] || raise('missing request_path!'))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def description
|
|
45
|
+
@raw[:route][:description] || @raw[:route][:desc] rescue nil
|
|
46
|
+
end
|
|
47
|
+
|
|
32
48
|
protected
|
|
33
49
|
|
|
34
50
|
def initialize(raw)
|
data/lib/rack/app/file_server.rb
CHANGED
data/lib/rack/app/router.rb
CHANGED
|
@@ -17,43 +17,38 @@ class Rack::App::Router
|
|
|
17
17
|
|
|
18
18
|
endpoints = self.endpoints
|
|
19
19
|
|
|
20
|
-
wd0 = endpoints.map { |endpoint| endpoint
|
|
21
|
-
wd1 = endpoints.map { |endpoint| endpoint
|
|
22
|
-
wd2 = endpoints.map { |endpoint|
|
|
20
|
+
wd0 = endpoints.map { |endpoint| endpoint.request_method.to_s.length }.max
|
|
21
|
+
wd1 = endpoints.map { |endpoint| endpoint.request_path.to_s.length }.max
|
|
22
|
+
wd2 = endpoints.map { |endpoint| endpoint.description.to_s.length }.max
|
|
23
23
|
|
|
24
|
-
return endpoints.sort_by { |endpoint| [endpoint
|
|
24
|
+
return endpoints.sort_by { |endpoint| [endpoint.request_method, endpoint.request_path] }.map do |endpoint|
|
|
25
25
|
[
|
|
26
|
-
endpoint
|
|
27
|
-
endpoint
|
|
28
|
-
|
|
26
|
+
endpoint.request_method.to_s.ljust(wd0),
|
|
27
|
+
endpoint.request_path.to_s.ljust(wd1),
|
|
28
|
+
endpoint.description.to_s.ljust(wd2)
|
|
29
29
|
].join(' ')
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
def register_endpoint!(
|
|
35
|
-
router = router_for(request_path)
|
|
36
|
-
router.register_endpoint!(
|
|
34
|
+
def register_endpoint!(endpoint)
|
|
35
|
+
router = router_for(endpoint.request_path)
|
|
36
|
+
router.register_endpoint!(endpoint)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def merge_router!(router, prop={})
|
|
40
40
|
raise(ArgumentError, 'invalid router object, must implement :endpoints interface') unless router.respond_to?(:endpoints)
|
|
41
41
|
router.endpoints.each do |endpoint|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
register_endpoint!(
|
|
45
|
-
endpoint[:request_method],
|
|
46
|
-
request_path,
|
|
47
|
-
endpoint[:endpoint],
|
|
48
|
-
endpoint[:properties]
|
|
49
|
-
)
|
|
42
|
+
new_request_path = ::Rack::App::Utils.join(prop[:namespaces], endpoint.request_path)
|
|
43
|
+
new_endpoint = endpoint.fork(:request_path => new_request_path)
|
|
44
|
+
register_endpoint!(new_endpoint)
|
|
50
45
|
end
|
|
51
46
|
nil
|
|
52
47
|
end
|
|
53
48
|
|
|
54
49
|
def reset
|
|
55
50
|
[@static, @dynamic].each(&:reset)
|
|
56
|
-
end
|
|
51
|
+
end
|
|
57
52
|
|
|
58
53
|
protected
|
|
59
54
|
|
|
@@ -74,9 +69,4 @@ class Rack::App::Router
|
|
|
74
69
|
path_str.include?(Rack::App::Constants::RACK_BASED_APPLICATION)
|
|
75
70
|
end
|
|
76
71
|
|
|
77
|
-
def extract_description(endpoint_struct)
|
|
78
|
-
if endpoint_struct[:properties]
|
|
79
|
-
endpoint_struct[:properties][:description]
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
72
|
end
|
data/lib/rack/app/router/base.rb
CHANGED
|
@@ -16,18 +16,9 @@ class Rack::App::Router::Base
|
|
|
16
16
|
@endpoints ||= []
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def register_endpoint!(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
{
|
|
23
|
-
:request_method => request_method,
|
|
24
|
-
:request_path => normalized_request_path,
|
|
25
|
-
:endpoint => endpoint,
|
|
26
|
-
:properties => properties
|
|
27
|
-
}
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
compile_endpoint!(request_method, normalized_request_path, endpoint)
|
|
19
|
+
def register_endpoint!(endpoint)
|
|
20
|
+
endpoints.push(endpoint)
|
|
21
|
+
compile_endpoint!(endpoint)
|
|
31
22
|
return endpoint
|
|
32
23
|
end
|
|
33
24
|
|
|
@@ -38,7 +29,7 @@ class Rack::App::Router::Base
|
|
|
38
29
|
|
|
39
30
|
protected
|
|
40
31
|
|
|
41
|
-
def compile_endpoint!(
|
|
32
|
+
def compile_endpoint!(endpoint)
|
|
42
33
|
raise(NotImplementedError)
|
|
43
34
|
end
|
|
44
35
|
|
|
@@ -38,12 +38,15 @@ class Rack::App::Router::Dynamic < Rack::App::Router::Base
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def compile_registered_endpoints!
|
|
41
|
-
endpoints.each do |
|
|
42
|
-
compile_endpoint!(
|
|
41
|
+
endpoints.each do |endpoint|
|
|
42
|
+
compile_endpoint!(endpoint)
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
def compile_endpoint!(
|
|
46
|
+
def compile_endpoint!(endpoint)
|
|
47
|
+
request_method = endpoint.request_method
|
|
48
|
+
request_path = endpoint.request_path
|
|
49
|
+
|
|
47
50
|
clusters_for(request_method) do |current_cluster|
|
|
48
51
|
|
|
49
52
|
break_build = false
|
|
@@ -15,13 +15,14 @@ class Rack::App::Router::Static < Rack::App::Router::Base
|
|
|
15
15
|
mapped_endpoint_routes.clear
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def compile_endpoint!(
|
|
19
|
-
|
|
18
|
+
def compile_endpoint!(endpoint)
|
|
19
|
+
routing_key = [endpoint.request_method, endpoint.request_path]
|
|
20
|
+
mapped_endpoint_routes[routing_key]= as_app(endpoint)
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
def compile_registered_endpoints!
|
|
23
24
|
endpoints.each do |endpoint|
|
|
24
|
-
compile_endpoint!(endpoint
|
|
25
|
+
compile_endpoint!(endpoint)
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
|
data/lib/rack/app/serializer.rb
CHANGED
|
@@ -2,12 +2,8 @@ class Rack::App::Serializer
|
|
|
2
2
|
|
|
3
3
|
attr_reader :logic
|
|
4
4
|
|
|
5
|
-
def initialize
|
|
6
|
-
@logic = lambda { |o| o.to_s }
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def set_serialization_logic(proc)
|
|
10
|
-
@logic = proc
|
|
5
|
+
def initialize(&block)
|
|
6
|
+
@logic = block || lambda { |o| o.to_s }
|
|
11
7
|
end
|
|
12
8
|
|
|
13
9
|
def serialize(object)
|
|
@@ -33,7 +33,7 @@ module Rack::App::SingletonMethods::HttpMethods
|
|
|
33
33
|
def link(path = '/', &block)
|
|
34
34
|
add_route(::Rack::App::Constants::HTTP::METHOD::LINK, path, &block)
|
|
35
35
|
end
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
def unlink(path = '/', &block)
|
|
38
38
|
add_route(::Rack::App::Constants::HTTP::METHOD::UNLINK, path, &block)
|
|
39
39
|
end
|
|
@@ -46,11 +46,9 @@ module Rack::App::SingletonMethods::HttpMethods
|
|
|
46
46
|
new_request_path = Rack::App::Utils.normalize_path(new_request_path)
|
|
47
47
|
original_request_path = Rack::App::Utils.normalize_path(original_request_path)
|
|
48
48
|
|
|
49
|
-
router.endpoints.select { |ep| ep
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
endpoint[:endpoint], endpoint[:properties]
|
|
53
|
-
)
|
|
49
|
+
router.endpoints.select { |ep| ep.request_path == original_request_path }.each do |endpoint|
|
|
50
|
+
new_endpoint = endpoint.fork(:request_path => new_request_path)
|
|
51
|
+
router.register_endpoint!(new_endpoint)
|
|
54
52
|
end
|
|
55
53
|
end
|
|
56
54
|
|
|
@@ -17,10 +17,18 @@ module Rack::App::SingletonMethods::Middleware
|
|
|
17
17
|
|
|
18
18
|
protected
|
|
19
19
|
|
|
20
|
-
def
|
|
21
|
-
@
|
|
22
|
-
@
|
|
23
|
-
@
|
|
20
|
+
def next_endpoint_middlewares(&block)
|
|
21
|
+
@next_endpoint_middlewares ||= []
|
|
22
|
+
@next_endpoint_middlewares << block unless block.nil?
|
|
23
|
+
@next_endpoint_middlewares
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
alias only_next_endpoint_middlewares next_endpoint_middlewares
|
|
27
|
+
|
|
28
|
+
Rack::App::Utils.deprecate(self,
|
|
29
|
+
:only_next_endpoint_middlewares,
|
|
30
|
+
:next_endpoint_middlewares,
|
|
31
|
+
2016,9
|
|
32
|
+
)
|
|
33
|
+
|
|
26
34
|
end
|
|
@@ -2,6 +2,17 @@ module Rack::App::SingletonMethods::Mounting
|
|
|
2
2
|
MOUNT = Rack::App::SingletonMethods::Mounting
|
|
3
3
|
|
|
4
4
|
def mount(app, options={})
|
|
5
|
+
case
|
|
6
|
+
when app.is_a?(Class) && app < ::Rack::App
|
|
7
|
+
mount_rack_app(app, options)
|
|
8
|
+
when app.respond_to?(:call)
|
|
9
|
+
mount_rack_interface_compatible_application(app, options)
|
|
10
|
+
else
|
|
11
|
+
raise(NotImplementedError)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def mount_rack_app(app, options={})
|
|
5
16
|
options.freeze
|
|
6
17
|
|
|
7
18
|
unless app.is_a?(Class) and app <= Rack::App
|
|
@@ -35,23 +46,45 @@ module Rack::App::SingletonMethods::Mounting
|
|
|
35
46
|
end
|
|
36
47
|
|
|
37
48
|
alias create_endpoints_for_files_in mount_directory
|
|
49
|
+
Rack::App::Utils.deprecate(self,:create_endpoints_for_files_in, :mount_directory, 2016,9)
|
|
38
50
|
|
|
39
51
|
def serve_files_from(file_path, options={})
|
|
40
52
|
file_server = Rack::App::FileServer.new(Rack::App::Utils.expand_path(file_path))
|
|
41
53
|
request_path = Rack::App::Utils.join(@namespaces, options[:to], '**', '*')
|
|
42
|
-
|
|
54
|
+
|
|
55
|
+
endpoint = Rack::App::Endpoint.new(
|
|
56
|
+
route_registration_properties.merge(
|
|
57
|
+
:request_method => 'GET',
|
|
58
|
+
:request_path => request_path,
|
|
59
|
+
:application => file_server
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
router.register_endpoint!(endpoint)
|
|
64
|
+
route_registration_properties.clear
|
|
65
|
+
nil
|
|
43
66
|
end
|
|
44
67
|
|
|
45
|
-
def
|
|
68
|
+
def mount_rack_interface_compatible_application(rack_based_app, options={})
|
|
46
69
|
router.register_endpoint!(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
70
|
+
Rack::App::Endpoint.new(
|
|
71
|
+
route_registration_properties.merge(
|
|
72
|
+
:request_method => ::Rack::App::Constants::HTTP::METHOD::ANY,
|
|
73
|
+
:request_path => Rack::App::Utils.join(
|
|
74
|
+
@namespaces,
|
|
75
|
+
options[:to],
|
|
76
|
+
::Rack::App::Constants::RACK_BASED_APPLICATION
|
|
77
|
+
),
|
|
78
|
+
:application => rack_based_app
|
|
79
|
+
)
|
|
80
|
+
)
|
|
51
81
|
)
|
|
52
82
|
end
|
|
53
83
|
|
|
54
|
-
alias
|
|
84
|
+
alias mount_rack_based_application mount_rack_interface_compatible_application
|
|
85
|
+
Rack::App::Utils.deprecate(self,:mount_rack_based_application, "mount or mount_rack_interface_compatible_application", 2016,9)
|
|
86
|
+
alias mount_app mount_rack_interface_compatible_application
|
|
87
|
+
Rack::App::Utils.deprecate(self,:mount_app, "mount or mount_rack_interface_compatible_application", 2016,9)
|
|
55
88
|
|
|
56
89
|
protected
|
|
57
90
|
|
|
@@ -2,7 +2,7 @@ module Rack::App::SingletonMethods::ParamsValidator
|
|
|
2
2
|
def validate_params(&block)
|
|
3
3
|
descriptor = Rack::App::Middlewares::Params::Definition.new(&block).to_descriptor
|
|
4
4
|
route_registration_properties[:params]= descriptor
|
|
5
|
-
|
|
5
|
+
next_endpoint_middlewares do |builder|
|
|
6
6
|
builder.use(Rack::App::Middlewares::Params::Setter)
|
|
7
7
|
builder.use(Rack::App::Middlewares::Params::Validator, descriptor)
|
|
8
8
|
builder.use(Rack::App::Middlewares::Params::Parser, descriptor)
|
|
@@ -22,24 +22,22 @@ module Rack::App::SingletonMethods::RouteHandling
|
|
|
22
22
|
|
|
23
23
|
def add_route(request_method, request_path, &block)
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
:user_defined_logic => block,
|
|
29
|
-
:request_method => request_method,
|
|
30
|
-
:request_path => request_path,
|
|
25
|
+
router.register_endpoint!(
|
|
26
|
+
Rack::App::Endpoint.new({
|
|
27
|
+
:app_class => self,
|
|
31
28
|
:error_handler => error,
|
|
32
29
|
:serializer => serializer,
|
|
33
|
-
:
|
|
34
|
-
:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
:user_defined_logic => block,
|
|
31
|
+
:request_method => request_method,
|
|
32
|
+
:route => route_registration_properties.dup,
|
|
33
|
+
:middleware_builders_blocks => next_endpoint_middlewares.dup,
|
|
34
|
+
:request_path => ::Rack::App::Utils.join(@namespaces, request_path)
|
|
35
|
+
})
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
next_endpoint_middlewares.clear
|
|
39
|
+
route_registration_properties.clear
|
|
40
|
+
return nil
|
|
43
41
|
|
|
44
42
|
end
|
|
45
43
|
|
|
@@ -10,11 +10,7 @@ module Rack::App::SingletonMethods::Settings
|
|
|
10
10
|
|
|
11
11
|
def serializer(&definition_how_to_serialize)
|
|
12
12
|
@serializer ||= Rack::App::Serializer.new
|
|
13
|
-
|
|
14
|
-
unless definition_how_to_serialize.nil?
|
|
15
|
-
@serializer.set_serialization_logic(definition_how_to_serialize)
|
|
16
|
-
end
|
|
17
|
-
|
|
13
|
+
@serializer = Rack::App::Serializer.new(&definition_how_to_serialize) unless definition_how_to_serialize.nil?
|
|
18
14
|
return @serializer
|
|
19
15
|
end
|
|
20
16
|
|
data/lib/rack/app/utils.rb
CHANGED
|
@@ -129,4 +129,27 @@ module Rack::App::Utils
|
|
|
129
129
|
CGI.escape(str.to_s)
|
|
130
130
|
end
|
|
131
131
|
|
|
132
|
+
##
|
|
133
|
+
# Simple deprecation method that deprecates +name+ by wrapping it up
|
|
134
|
+
# in a dummy method. It warns on each call to the dummy method
|
|
135
|
+
# telling the user of +repl+ (unless +repl+ is :none) and the
|
|
136
|
+
# year/month that it is planned to go away.
|
|
137
|
+
def deprecate(object, name, repl, year, month)
|
|
138
|
+
object.class_eval {
|
|
139
|
+
old = "_deprecated_#{name}"
|
|
140
|
+
alias_method old, name
|
|
141
|
+
define_method name do |*args, &block|
|
|
142
|
+
klass = self.kind_of? Module
|
|
143
|
+
target = klass ? "#{self}." : "#{self.class}#"
|
|
144
|
+
msg = [ "NOTE: #{target}#{name} is deprecated",
|
|
145
|
+
repl == :none ? " with no replacement" : "; use #{repl} instead",
|
|
146
|
+
". It will be removed on or after %4d-%02d-01." % [year, month],
|
|
147
|
+
"\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",
|
|
148
|
+
]
|
|
149
|
+
warn "#{msg.join}."
|
|
150
|
+
__send__(old, *args, &block)
|
|
151
|
+
end
|
|
152
|
+
}
|
|
153
|
+
end
|
|
154
|
+
|
|
132
155
|
end
|
data/spec_files.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
./spec/benchmark_spec.rb ./spec/rack/app/alias_endpoint_spec.rb ./spec/rack/app/bundled_extensions/logger_spec.rb ./spec/rack/app/cli_spec.rb ./spec/rack/app/endpoint_spec.rb ./spec/rack/app/extension_spec.rb ./spec/rack/app/file_server_spec.rb ./spec/rack/app/hooks_spec.rb ./spec/rack/app/inheritance_spec.rb ./spec/rack/app/instance_methods_spec.rb ./spec/rack/app/middlewares/header_setter_spec.rb ./spec/rack/app/mounting_spec.rb ./spec/rack/app/not_found_spec.rb ./spec/rack/app/
|
|
1
|
+
./spec/benchmark_spec.rb ./spec/rack/app/alias_endpoint_spec.rb ./spec/rack/app/bundled_extensions/logger_spec.rb ./spec/rack/app/cli_spec.rb ./spec/rack/app/endpoint_spec.rb ./spec/rack/app/extension_spec.rb ./spec/rack/app/file_server_spec.rb ./spec/rack/app/hooks_spec.rb ./spec/rack/app/inheritance_spec.rb ./spec/rack/app/instance_methods_spec.rb ./spec/rack/app/middlewares/header_setter_spec.rb ./spec/rack/app/mounting_spec.rb ./spec/rack/app/not_found_spec.rb ./spec/rack/app/next_endpoint_middlewares_spec.rb ./spec/rack/app/params_validation_spec/with_real_class_spec.rb ./spec/rack/app/params_validation_spec.rb ./spec/rack/app/redirect_spec.rb ./spec/rack/app/request_configurator_spec.rb ./spec/rack/app/router/dynamic_spec.rb ./spec/rack/app/router/static_spec.rb ./spec/rack/app/router_spec.rb ./spec/rack/app/streaming_spec.rb ./spec/rack/app/test_spec.rb ./spec/rack/app/utils/deep_dup_spec.rb ./spec/rack/app/utils/parser_spec.rb ./spec/rack/app/utils_spec.rb ./spec/rack/app_spec.rb
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'benchmark'
|
|
2
|
+
|
|
3
|
+
VALUE = 'OK'
|
|
4
|
+
class A
|
|
5
|
+
attr_accessor :value
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class B
|
|
9
|
+
def value=(new_value)
|
|
10
|
+
@value = new_value
|
|
11
|
+
end
|
|
12
|
+
def value
|
|
13
|
+
@value
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class C
|
|
18
|
+
attr_reader :value
|
|
19
|
+
def value=(new_value)
|
|
20
|
+
@value = new_value
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
a = A.new
|
|
25
|
+
a.value= VALUE
|
|
26
|
+
|
|
27
|
+
b = B.new
|
|
28
|
+
b.value= VALUE
|
|
29
|
+
|
|
30
|
+
c = C.new
|
|
31
|
+
c.value= VALUE
|
|
32
|
+
|
|
33
|
+
o = Object.new
|
|
34
|
+
o.define_singleton_method(:value){ VALUE }
|
|
35
|
+
|
|
36
|
+
h = {:value => VALUE}
|
|
37
|
+
|
|
38
|
+
TEST_AMOUNT = 10_000_000
|
|
39
|
+
|
|
40
|
+
Benchmark.bm(30) do |x|
|
|
41
|
+
|
|
42
|
+
x.report('attr_accessor') do
|
|
43
|
+
TEST_AMOUNT.times do
|
|
44
|
+
a.value
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
x.report('defined + instance var') do
|
|
49
|
+
TEST_AMOUNT.times do
|
|
50
|
+
b.value
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
x.report('defined setter + attr_reader') do
|
|
55
|
+
TEST_AMOUNT.times do
|
|
56
|
+
c.value
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
x.report('attr_reader + __send__') do
|
|
61
|
+
TEST_AMOUNT.times do
|
|
62
|
+
c.__send__(:value)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
x.report('anonimus method call') do
|
|
67
|
+
TEST_AMOUNT.times do
|
|
68
|
+
o.value
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
x.report('hash getter') do
|
|
73
|
+
TEST_AMOUNT.times do
|
|
74
|
+
h[:value]
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
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: 5.
|
|
4
|
+
version: 5.3.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: 2016-
|
|
11
|
+
date: 2016-09-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -106,8 +106,9 @@ files:
|
|
|
106
106
|
- lib/rack/app/cli/runner.rb
|
|
107
107
|
- lib/rack/app/constants.rb
|
|
108
108
|
- lib/rack/app/endpoint.rb
|
|
109
|
+
- lib/rack/app/endpoint/builder.rb
|
|
110
|
+
- lib/rack/app/endpoint/config.rb
|
|
109
111
|
- lib/rack/app/endpoint/executor.rb
|
|
110
|
-
- lib/rack/app/endpoint/properties.rb
|
|
111
112
|
- lib/rack/app/error_handler.rb
|
|
112
113
|
- lib/rack/app/extension.rb
|
|
113
114
|
- lib/rack/app/file_server.rb
|
|
@@ -175,6 +176,7 @@ files:
|
|
|
175
176
|
- spec_files.txt
|
|
176
177
|
- spike/array_vs_proc.rb
|
|
177
178
|
- spike/long_endpoint.rb
|
|
179
|
+
- spike/method_vs_hash.rb
|
|
178
180
|
- spike/method_vs_instance_exec.rb
|
|
179
181
|
- spike/return_vs_throw.rb
|
|
180
182
|
- src/Net__HTTP Cheat Sheet.pdf
|