rack-app 0.20.0 → 0.21.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/README.md +18 -22
- data/VERSION +1 -1
- data/lib/rack/app.rb +15 -3
- data/lib/rack/app/file/server.rb +12 -17
- data/lib/rack/app/router.rb +9 -2
- data/lib/rack/app/utils.rb +1 -0
- 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: e8f30ea2966178d44130dd772b67065dedc3dc16
|
4
|
+
data.tar.gz: b711bfd0492d8c1d53ed280fa46fd5b7bd5e93e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df68e6acce0723868caf5f6f8f88aa52a9113763f9b0d7c71fc233558955f627f905309cbe505adb7ba2cdf615d5a6a0c58215c623192f2a9d12d6d77fe3256b
|
7
|
+
data.tar.gz: 46c05c5677227ae13983f81cf75c0215dbb061b7ef4805ac8add5ce011587606acfc9377d8d2c0c3e15ed29972978641d3c94f2edb6eb9a4dd7a7c8f9545c5a9
|
data/README.md
CHANGED
@@ -88,13 +88,17 @@ class App < Rack::App
|
|
88
88
|
return 'Hello World!'
|
89
89
|
end
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
namespace '/users' do
|
92
|
+
|
93
|
+
desc 'some restful endpoint'
|
94
|
+
get '/:user_id' do
|
95
|
+
response.status = 201
|
96
|
+
params['user_id'] #=> restful parameter :user_id
|
97
|
+
say #=> "hello world!"
|
98
|
+
end
|
99
|
+
|
96
100
|
end
|
97
|
-
|
101
|
+
|
98
102
|
desc 'some endpoint that has error and will be rescued'
|
99
103
|
get '/make_error' do
|
100
104
|
raise(StandardError,'error block rescued')
|
@@ -176,23 +180,15 @@ end
|
|
176
180
|
|
177
181
|
## [Benchmarking](https://github.com/adamluzsi/rack-app.rb-benchmark)
|
178
182
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
* with routing
|
187
|
-
* with value parsing and reponse object building
|
188
|
-
|
189
|
-
* Rack::App 9.995314276086763x faster (0.00026966415800000693 sec) that Grape::API
|
190
|
-
* returning a simple rack response array without any logic is 12.395832480544698x faster (2.7559874999978477e-05 sec) that Rack::App
|
191
|
-
* the same dumb empty proc call is 123.90024135676842x faster than Grape::API (0.0002972240329999854 sec)
|
183
|
+
RackSkeleton avg duration: 5.2298899999950066e-06 s
|
184
|
+
Rack::App avg duration: 3.323366999999523e-05 s
|
185
|
+
Grape::API avg duration: 0.00031554329000000426 s
|
186
|
+
|
187
|
+
Rack::App 9.494686864256929x faster (0.000282309620000009 sec) that Grape::API
|
188
|
+
RackSkeleton 6.354563862725021x faster (2.800378000000022e-05 sec) that Rack::App
|
189
|
+
RackSkeleton 60.33459403549703x faster (0.00031031340000000924 sec) than Grape::API
|
192
190
|
|
193
|
-
|
194
|
-
I feared do this for Rails that is usually slower than Grape :S
|
195
|
-
To be honest, I measured with grape because that is one of my favorite micro framework
|
191
|
+
To be honest, I measured with grape because that is one of my favorite micro framework!
|
196
192
|
|
197
193
|
## Roadmap
|
198
194
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.21.0
|
data/lib/rack/app.rb
CHANGED
@@ -89,6 +89,8 @@ class Rack::App
|
|
89
89
|
|
90
90
|
def add_route(request_method, request_path, &block)
|
91
91
|
|
92
|
+
request_path = ::Rack::App::Utils.join(@namespaces, request_path)
|
93
|
+
|
92
94
|
properties = endpoint_properties.merge(
|
93
95
|
{
|
94
96
|
:user_defined_logic => block,
|
@@ -108,18 +110,19 @@ class Rack::App
|
|
108
110
|
def serve_files_from(relative_path, options={})
|
109
111
|
options.merge!(endpoint_properties)
|
110
112
|
file_server = Rack::App::File::Server.new(relative_path, options)
|
111
|
-
request_path = Rack::App::Utils.join(file_server.namespace, '**', '*')
|
113
|
+
request_path = Rack::App::Utils.join(@namespaces, options[:to], file_server.namespace, '**', '*')
|
112
114
|
router.register_endpoint!('GET', request_path, @last_description, file_server)
|
113
115
|
@last_description = nil
|
114
116
|
end
|
115
117
|
|
116
|
-
def mount(api_class)
|
118
|
+
def mount(api_class, mount_prop={})
|
117
119
|
|
118
120
|
unless api_class.is_a?(Class) and api_class <= Rack::App
|
119
121
|
raise(ArgumentError, 'Invalid class given for mount, must be a Rack::App')
|
120
122
|
end
|
121
123
|
|
122
|
-
|
124
|
+
merge_prop = {:namespaces => [@namespaces, mount_prop[:to]].flatten}
|
125
|
+
router.merge_router!(api_class.router, merge_prop)
|
123
126
|
|
124
127
|
return nil
|
125
128
|
end
|
@@ -140,6 +143,15 @@ class Rack::App
|
|
140
143
|
@headers
|
141
144
|
end
|
142
145
|
|
146
|
+
def namespace(request_path_namespace)
|
147
|
+
return unless block_given?
|
148
|
+
@namespaces ||= []
|
149
|
+
@namespaces.push(request_path_namespace)
|
150
|
+
yield
|
151
|
+
@namespaces.pop
|
152
|
+
nil
|
153
|
+
end
|
154
|
+
|
143
155
|
protected
|
144
156
|
|
145
157
|
def endpoint_properties
|
data/lib/rack/app/file/server.rb
CHANGED
@@ -4,16 +4,21 @@ class Rack::App::File::Server
|
|
4
4
|
|
5
5
|
def initialize(root_folder, options={})
|
6
6
|
require 'rack/file'
|
7
|
-
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@rack_file_server = ::Rack::File.new(Rack::App::Utils.pwd(root_folder), {})
|
12
|
-
|
7
|
+
@raw_root_folder = root_folder
|
8
|
+
@root_folder = Rack::App::Utils.pwd(@raw_root_folder)
|
9
|
+
@relative_file_paths = Dir.glob(File.join(@root_folder,'**','*')).map{|file_path| file_path.sub(@root_folder,'') }.sort_by{|str| str.length }.reverse
|
10
|
+
@rack_file_server = ::Rack::File.new(@root_folder, {})
|
13
11
|
end
|
14
12
|
|
15
13
|
def call(env)
|
16
|
-
|
14
|
+
path_info = clean_path_info(env)
|
15
|
+
|
16
|
+
@relative_file_paths.each do |relative_file_path|
|
17
|
+
if path_info =~ /#{Regexp.escape(relative_file_path)}$/
|
18
|
+
env[::Rack::PATH_INFO]= relative_file_path
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
17
22
|
@rack_file_server.call(env)
|
18
23
|
end
|
19
24
|
|
@@ -22,16 +27,6 @@ class Rack::App::File::Server
|
|
22
27
|
|
23
28
|
protected
|
24
29
|
|
25
|
-
def raw_namespace(options)
|
26
|
-
options[:to] || '/'
|
27
|
-
end
|
28
|
-
|
29
|
-
def formatted_namespace(options)
|
30
|
-
namespace = raw_namespace(options).to_s.sub(/^\//, '').sub(/\/$/, '')
|
31
|
-
namespace += '/' unless namespace.empty?
|
32
|
-
namespace
|
33
|
-
end
|
34
|
-
|
35
30
|
def clean_path_info(env)
|
36
31
|
path_info = ::Rack::Utils.unescape(env[::Rack::PATH_INFO])
|
37
32
|
return clean_path_info = ::Rack::Utils.clean_path_info(path_info)
|
data/lib/rack/app/router.rb
CHANGED
@@ -37,10 +37,17 @@ class Rack::App::Router
|
|
37
37
|
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
40
|
+
def merge_router!(router,prop={})
|
41
41
|
raise(ArgumentError, 'invalid router object, must implement :endpoints interface') unless router.respond_to?(:endpoints)
|
42
42
|
router.endpoints.each do |endpoint|
|
43
|
-
|
43
|
+
request_path = ::Rack::App::Utils.join(prop[:namespaces], endpoint[:request_path])
|
44
|
+
|
45
|
+
register_endpoint!(
|
46
|
+
endpoint[:request_method],
|
47
|
+
request_path,
|
48
|
+
endpoint[:description],
|
49
|
+
endpoint[:endpoint]
|
50
|
+
)
|
44
51
|
end
|
45
52
|
nil
|
46
53
|
end
|
data/lib/rack/app/utils.rb
CHANGED
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.21.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-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|