rack-app 5.1.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/README.md +1 -3
- data/VERSION +1 -1
- data/lib/rack/app/middlewares/configuration.rb +3 -0
- data/lib/rack/app/middlewares/configuration/path_info_formatter.rb +14 -0
- data/lib/rack/app/middlewares/configuration/path_params_matcher.rb +14 -0
- data/lib/rack/app/router/base.rb +7 -6
- data/lib/rack/app/router/dynamic.rb +13 -14
- data/lib/rack/app/router/static.rb +5 -2
- data/lib/rack/app/test.rb +7 -9
- data/lib/rack/app/test/singleton_methods.rb +9 -4
- data/lib/rack/app/test/utils.rb +0 -6
- data/spike/long_endpoint.rb +29 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10f50fab86de1a0048be77118f717f557c3fcfc9
|
4
|
+
data.tar.gz: 84ec803fcb8677e60b56ef0b7c1362f792f62e2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ed0aeb5c5e1969ded36b657d28265f1b9d5cec2120d9277a5515ec0ab441154bbb1744d6f03de288ce853daa471fe5175bf9354a30f2daa1c4ae1f52c4cf8c5
|
7
|
+
data.tar.gz: 5548b69b220ba01de870451750cb624b0e94f4ce41fb5bdb92b8563ebde88095c7bb46a74d53f744491e1684a231e27233fb2d9e533c1ea906a3454e2b75522d
|
data/.travis.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
language: ruby
|
2
|
-
script: rspec spec
|
2
|
+
script: rspec spec -f d
|
3
3
|
|
4
4
|
install:
|
5
5
|
- gem update bundler
|
@@ -32,7 +32,7 @@ env:
|
|
32
32
|
- VERBOSE=true
|
33
33
|
- TIMEOUT=1
|
34
34
|
- BENCHMARK_QUANTITY=100000
|
35
|
-
- STREAM_FILE_SIZE=
|
35
|
+
- STREAM_FILE_SIZE=68
|
36
36
|
|
37
37
|
branches:
|
38
38
|
only:
|
data/README.md
CHANGED
@@ -4,8 +4,6 @@
|
|
4
4
|
[travis-link]: http://travis-ci.org/rack-app/rack-app
|
5
5
|
[travis-home]: http://travis-ci.org/
|
6
6
|
|
7
|
-
![Rack::App](http://rack-app-website.herokuapp.com/img/msruby_old.png)
|
8
|
-
|
9
7
|
Your next favourite rack based micro framework that is totally addition free!
|
10
8
|
Have a cup of awesomeness with your performance designed framework!
|
11
9
|
|
@@ -169,7 +167,7 @@ class App < Rack::App
|
|
169
167
|
stream do |out|
|
170
168
|
out << 'data row'
|
171
169
|
end
|
172
|
-
end
|
170
|
+
end
|
173
171
|
|
174
172
|
end
|
175
173
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.
|
1
|
+
5.2.0
|
@@ -2,6 +2,9 @@ require "rack/request"
|
|
2
2
|
require "rack/response"
|
3
3
|
class Rack::App::Middlewares::Configuration
|
4
4
|
|
5
|
+
require "rack/app/middlewares/configuration/path_info_formatter"
|
6
|
+
require "rack/app/middlewares/configuration/path_params_matcher"
|
7
|
+
|
5
8
|
def initialize(app, options={})
|
6
9
|
@handler_class = options[:app_class] || raise
|
7
10
|
@serializer = options[:serializer] || raise
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Rack::App::Middlewares::Configuration::PathInfoFormatter
|
2
|
+
|
3
|
+
def initialize(app, cut_string_from_path)
|
4
|
+
@cut_string_from_path = cut_string_from_path
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
env[::Rack::App::Constants::ENV::ORIGINAL_PATH_INFO]= env[::Rack::PATH_INFO].dup
|
10
|
+
env[::Rack::PATH_INFO].sub!(@cut_string_from_path, '')
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Rack::App::Middlewares::Configuration::PathParamsMatcher
|
2
|
+
|
3
|
+
def initialize(app, path_params)
|
4
|
+
@path_params = path_params
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
env[::Rack::App::Constants::ENV::PATH_PARAMS_MATCHER]= @path_params.dup
|
10
|
+
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/lib/rack/app/router/base.rb
CHANGED
@@ -8,29 +8,26 @@ class Rack::App::Router::Base
|
|
8
8
|
context = fetch_context(request_method, path_info)
|
9
9
|
return unless context.is_a?(Hash) and not context[:app].nil?
|
10
10
|
|
11
|
-
format_env(context, env)
|
12
11
|
context[:app].call(env)
|
13
|
-
|
14
12
|
end
|
15
13
|
|
16
|
-
def format_env(context, env)
|
17
|
-
end
|
18
14
|
|
19
15
|
def endpoints
|
20
16
|
@endpoints ||= []
|
21
17
|
end
|
22
18
|
|
23
19
|
def register_endpoint!(request_method, request_path, endpoint, properties={})
|
20
|
+
normalized_request_path = Rack::App::Utils.normalize_path(request_path)
|
24
21
|
endpoints.push(
|
25
22
|
{
|
26
23
|
:request_method => request_method,
|
27
|
-
:request_path =>
|
24
|
+
:request_path => normalized_request_path,
|
28
25
|
:endpoint => endpoint,
|
29
26
|
:properties => properties
|
30
27
|
}
|
31
28
|
)
|
32
29
|
|
33
|
-
|
30
|
+
compile_endpoint!(request_method, normalized_request_path, endpoint)
|
34
31
|
return endpoint
|
35
32
|
end
|
36
33
|
|
@@ -41,6 +38,10 @@ class Rack::App::Router::Base
|
|
41
38
|
|
42
39
|
protected
|
43
40
|
|
41
|
+
def compile_endpoint!(request_method, request_path, endpoint)
|
42
|
+
raise(NotImplementedError)
|
43
|
+
end
|
44
|
+
|
44
45
|
def clean_routes!
|
45
46
|
raise(NotImplementedError)
|
46
47
|
end
|
@@ -39,18 +39,20 @@ class Rack::App::Router::Dynamic < Rack::App::Router::Base
|
|
39
39
|
|
40
40
|
def compile_registered_endpoints!
|
41
41
|
endpoints.each do |endpoint_prop|
|
42
|
-
compile_endpoint(endpoint_prop[:request_method], endpoint_prop[:request_path], endpoint_prop[:endpoint])
|
42
|
+
compile_endpoint!(endpoint_prop[:request_method], endpoint_prop[:request_path], endpoint_prop[:endpoint])
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def compile_endpoint(request_method, request_path, endpoint)
|
46
|
+
def compile_endpoint!(request_method, request_path, endpoint)
|
47
47
|
clusters_for(request_method) do |current_cluster|
|
48
48
|
|
49
49
|
break_build = false
|
50
50
|
path_params = {}
|
51
|
-
mount_path = ''
|
52
51
|
options = {}
|
53
52
|
|
53
|
+
builder = Rack::Builder.new
|
54
|
+
builder.use(Rack::App::Middlewares::Configuration::PathParamsMatcher, path_params)
|
55
|
+
|
54
56
|
request_path_parts = request_path.split('/')
|
55
57
|
request_path_parts.each.with_index do |path_part, index|
|
56
58
|
|
@@ -64,7 +66,10 @@ class Rack::App::Router::Dynamic < Rack::App::Router::Base
|
|
64
66
|
|
65
67
|
elsif path_part_is_a_mounted_rack_based_application?(path_part)
|
66
68
|
break_build = true
|
67
|
-
|
69
|
+
builder.use(
|
70
|
+
Rack::App::Middlewares::Configuration::PathInfoFormatter,
|
71
|
+
calculate_mount_path(request_path_parts)
|
72
|
+
)
|
68
73
|
MOUNTED_APPLICATION
|
69
74
|
|
70
75
|
else
|
@@ -76,16 +81,16 @@ class Rack::App::Router::Dynamic < Rack::App::Router::Base
|
|
76
81
|
|
77
82
|
end
|
78
83
|
|
79
|
-
|
84
|
+
|
85
|
+
builder.run(as_app(endpoint))
|
86
|
+
current_cluster[:app]= builder.to_app
|
87
|
+
|
80
88
|
current_cluster[:endpoint]= endpoint
|
81
89
|
if current_cluster[:endpoint].respond_to?(:register_path_params_matcher)
|
82
90
|
current_cluster[:endpoint].register_path_params_matcher(path_params)
|
83
91
|
end
|
84
92
|
|
85
|
-
options[:mount_path]= mount_path
|
86
|
-
options[:path_params]= path_params
|
87
93
|
current_cluster[:options]= options
|
88
|
-
|
89
94
|
end
|
90
95
|
end
|
91
96
|
|
@@ -146,10 +151,4 @@ class Rack::App::Router::Dynamic < Rack::App::Router::Base
|
|
146
151
|
|
147
152
|
end
|
148
153
|
|
149
|
-
def format_env(context, env)
|
150
|
-
mount_path = context[:options][:mount_path] rescue ''
|
151
|
-
env[::Rack::App::Constants::ENV::PATH_PARAMS_MATCHER]= context[:options][:path_params].dup
|
152
|
-
env[::Rack::PATH_INFO].sub!(mount_path, '')
|
153
|
-
end
|
154
|
-
|
155
154
|
end
|
@@ -15,10 +15,13 @@ class Rack::App::Router::Static < Rack::App::Router::Base
|
|
15
15
|
mapped_endpoint_routes.clear
|
16
16
|
end
|
17
17
|
|
18
|
+
def compile_endpoint!(request_method, request_path, endpoint)
|
19
|
+
mapped_endpoint_routes[[request_method.to_s.upcase, request_path]]= as_app(endpoint)
|
20
|
+
end
|
21
|
+
|
18
22
|
def compile_registered_endpoints!
|
19
23
|
endpoints.each do |endpoint|
|
20
|
-
|
21
|
-
mapped_endpoint_routes[[endpoint[:request_method].to_s.upcase, endpoint[:request_path]]]= app
|
24
|
+
compile_endpoint!(endpoint[:request_method],endpoint[:request_path], endpoint[:endpoint])
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
data/lib/rack/app/test.rb
CHANGED
@@ -26,18 +26,16 @@ module Rack::App::Test
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def rack_app(&block)
|
29
|
-
|
30
29
|
@rack_app ||= lambda do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
if defined?(__rack_app_class__)
|
31
|
+
__rack_app_class__
|
32
|
+
elsif defined?(described_class) && described_class.respond_to?(:call)
|
33
|
+
described_class
|
34
|
+
else
|
35
|
+
raise('missing class definition')
|
35
36
|
end
|
36
|
-
|
37
|
-
end.call
|
38
|
-
|
37
|
+
end.call
|
39
38
|
block.is_a?(Proc) ? @rack_app.instance_exec(&block) : @rack_app
|
40
|
-
|
41
39
|
end
|
42
40
|
|
43
41
|
end
|
@@ -1,9 +1,14 @@
|
|
1
1
|
module Rack::App::Test::SingletonMethods
|
2
2
|
|
3
3
|
def rack_app(rack_app_class=nil, &constructor)
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
klass = if !rack_app_class.nil? && rack_app_class.respond_to?(:call)
|
5
|
+
rack_app_class
|
6
|
+
else
|
7
|
+
Class.new(Rack::App)
|
8
|
+
end
|
9
|
+
|
10
|
+
klass.class_eval(&constructor) unless constructor.nil?
|
11
|
+
return in_this_context(:__rack_app_class__){ klass }
|
7
12
|
end
|
8
13
|
|
9
14
|
def in_this_context(name, &block)
|
@@ -12,4 +17,4 @@ module Rack::App::Test::SingletonMethods
|
|
12
17
|
define_method(name, &block)
|
13
18
|
end
|
14
19
|
|
15
|
-
end
|
20
|
+
end
|
data/lib/rack/app/test/utils.rb
CHANGED
@@ -10,12 +10,6 @@ module Rack::App::Test::Utils
|
|
10
10
|
properties
|
11
11
|
end
|
12
12
|
|
13
|
-
def rack_app_by(subject_class, constructors)
|
14
|
-
app_class = subject_class.respond_to?(:call) ? subject_class : Class.new(Rack::App)
|
15
|
-
constructors.each { |constructor| app_class.class_eval(&constructor) }
|
16
|
-
return app_class
|
17
|
-
end
|
18
|
-
|
19
13
|
def env_by(properties)
|
20
14
|
|
21
15
|
properties = format_properties(properties)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
rack_api_lib_folder = File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
$LOAD_PATH.unshift(rack_api_lib_folder)
|
3
|
+
|
4
|
+
require "rack/app"
|
5
|
+
require "rack/mock"
|
6
|
+
require "benchmark"
|
7
|
+
|
8
|
+
class App < Rack::App
|
9
|
+
|
10
|
+
get "/a/b/c/:d/e/f/:g/h/i/j/k/l/m/n/o/p/q/:something" do
|
11
|
+
return 'Hello, World!'
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
request = Rack::MockRequest.new(App)
|
18
|
+
|
19
|
+
Benchmark.bm do |x|
|
20
|
+
x.report do
|
21
|
+
request.get("/a/b/c/dog/e/f/goat/h/i/j/k/l/m/n/o/p/q/chicken" )
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
result = Benchmark.measure do
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
puts result
|
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.2.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-08-
|
11
|
+
date: 2016-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -119,6 +119,8 @@ files:
|
|
119
119
|
- lib/rack/app/instance_methods/streaming.rb
|
120
120
|
- lib/rack/app/middlewares.rb
|
121
121
|
- lib/rack/app/middlewares/configuration.rb
|
122
|
+
- lib/rack/app/middlewares/configuration/path_info_formatter.rb
|
123
|
+
- lib/rack/app/middlewares/configuration/path_params_matcher.rb
|
122
124
|
- lib/rack/app/middlewares/header_setter.rb
|
123
125
|
- lib/rack/app/middlewares/hooks.rb
|
124
126
|
- lib/rack/app/middlewares/hooks/after.rb
|
@@ -172,6 +174,7 @@ files:
|
|
172
174
|
- rack-app.gemspec
|
173
175
|
- spec_files.txt
|
174
176
|
- spike/array_vs_proc.rb
|
177
|
+
- spike/long_endpoint.rb
|
175
178
|
- spike/method_vs_instance_exec.rb
|
176
179
|
- spike/return_vs_throw.rb
|
177
180
|
- src/Net__HTTP Cheat Sheet.pdf
|