rack-app 0.21.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8f30ea2966178d44130dd772b67065dedc3dc16
4
- data.tar.gz: b711bfd0492d8c1d53ed280fa46fd5b7bd5e93e3
3
+ metadata.gz: dc6e00653368212644684d6ba3c19c409eee6bad
4
+ data.tar.gz: 165212d0e3eaba27ff27f0b3e2534d70864be7dc
5
5
  SHA512:
6
- metadata.gz: df68e6acce0723868caf5f6f8f88aa52a9113763f9b0d7c71fc233558955f627f905309cbe505adb7ba2cdf615d5a6a0c58215c623192f2a9d12d6d77fe3256b
7
- data.tar.gz: 46c05c5677227ae13983f81cf75c0215dbb061b7ef4805ac8add5ce011587606acfc9377d8d2c0c3e15ed29972978641d3c94f2edb6eb9a4dd7a7c8f9545c5a9
6
+ metadata.gz: 09b60839ee3b5a49f95c891f0b2c8a93be41503572c6943b313d42d0925e7be2a7c75625262da893c49bf2eac9707f53ad8ddae25d6c87fe0c8439fcb975c660
7
+ data.tar.gz: 5e808fc8b28adde7e389fd97f219ab9fde05d0a67d44bdab870e5e5aa18093f23f85aa5e1cfb9f1c5063dad9caf161d83792220704b60a571e6ade5dcc3d1134
data/README.md CHANGED
@@ -180,15 +180,20 @@ end
180
180
 
181
181
  ## [Benchmarking](https://github.com/adamluzsi/rack-app.rb-benchmark)
182
182
 
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
190
-
191
- To be honest, I measured with grape because that is one of my favorite micro framework!
183
+ | name | user | system | total | real |
184
+ |------------------|----------------------------|------------------------|-----------------------|------------------------|
185
+ | rack | 3.150000000000001e-05 | 1.3000000000000003e-06 | 3.280000000000001e-05 | 3.602101e-05 |
186
+ | rack-app | 0.0005159999999999999 | 1.4000000000000005e-05 | 0.0005300000000000001 | 0.0005141295 |
187
+ | ramaze | 0.0005166999999999999 | 1.98e-05 | 0.0005365 | 0.0005347348 |
188
+ | brooklyn | 0.0007564 | 3.700000000000001e-06 | 0.0007601000000000001 | 0.0007743060099999998 |
189
+ | nancy | 0.000812 | 5.900000000000001e-06 | 0.0008179000000000001 | 0.0008314749300000001 |
190
+ | scorched | 0.0008451000000000001 | 4.699999999999999e-06 | 0.0008498000000000001 | 0.00085131501 |
191
+ | sinatra | 0.0008465000000000001 | 7.000000000000001e-06 | 0.0008535000000000001 | 0.00086448211 |
192
+ | hobbit | 0.0013664 | 4.5e-06 | 0.0013709 | 0.0013804752700000004 |
193
+ | grape | 0.0018807 | 2.7800000000000005e-05 | 0.0019085 | 0.0019229531400000001 |
194
+ | rails | 0.0018995000000000001 | 7.06e-05 | 0.0019701 | 0.00198401458 |
195
+ | camping | 0.002921 | 7.24e-05 | 0.0029934000000000002 | 0.0030896778800000003 |
196
+ | cuba | 0.0034559000000000005 | 2.8600000000000004e-05 | 0.0034845 | 0.00349655002 |
192
197
 
193
198
  ## Roadmap
194
199
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.21.0
1
+ 0.22.0
@@ -91,13 +91,18 @@ class Rack::App
91
91
 
92
92
  request_path = ::Rack::App::Utils.join(@namespaces, request_path)
93
93
 
94
- properties = endpoint_properties.merge(
95
- {
96
- :user_defined_logic => block,
97
- :request_method => request_method,
98
- :request_path => request_path,
99
- }
100
- )
94
+ properties = {
95
+ :user_defined_logic => block,
96
+ :request_method => request_method,
97
+ :request_path => request_path,
98
+
99
+ :default_headers => headers,
100
+ :error_handler => error,
101
+ :description => @last_description,
102
+ :serializer => serializer,
103
+ :app_class => self
104
+ }
105
+
101
106
 
102
107
  endpoint = Rack::App::Endpoint.new(properties)
103
108
  router.register_endpoint!(request_method, request_path, @last_description, endpoint)
@@ -107,10 +112,9 @@ class Rack::App
107
112
 
108
113
  end
109
114
 
110
- def serve_files_from(relative_path, options={})
111
- options.merge!(endpoint_properties)
112
- file_server = Rack::App::File::Server.new(relative_path, options)
113
- request_path = Rack::App::Utils.join(@namespaces, options[:to], file_server.namespace, '**', '*')
115
+ def serve_files_from(file_path, options={})
116
+ file_server = Rack::App::File::Server.new(Rack::App::Utils.expand_path(file_path))
117
+ request_path = Rack::App::Utils.join(@namespaces, options[:to], '**', '*')
114
118
  router.register_endpoint!('GET', request_path, @last_description, file_server)
115
119
  @last_description = nil
116
120
  end
@@ -152,18 +156,6 @@ class Rack::App
152
156
  nil
153
157
  end
154
158
 
155
- protected
156
-
157
- def endpoint_properties
158
- {
159
- :default_headers => headers,
160
- :error_handler => error,
161
- :description => @last_description,
162
- :serializer => serializer,
163
- :app_class => self
164
- }
165
- end
166
-
167
159
  end
168
160
 
169
161
  def params
@@ -1,11 +1,8 @@
1
1
  class Rack::App::File::Server
2
2
 
3
- attr_reader :namespace, :properties
4
-
5
- def initialize(root_folder, options={})
3
+ def initialize(root_folder)
6
4
  require 'rack/file'
7
- @raw_root_folder = root_folder
8
- @root_folder = Rack::App::Utils.pwd(@raw_root_folder)
5
+ @root_folder = root_folder
9
6
  @relative_file_paths = Dir.glob(File.join(@root_folder,'**','*')).map{|file_path| file_path.sub(@root_folder,'') }.sort_by{|str| str.length }.reverse
10
7
  @rack_file_server = ::Rack::File.new(@root_folder, {})
11
8
  end
@@ -18,15 +18,26 @@ module Rack::App::Utils
18
18
  path
19
19
  end
20
20
 
21
+ # Based on ActiveSupport, removed inflections.
22
+ # https://github.com/rails/rails/blob/v4.1.0.rc1/activesupport/lib/active_support/inflector/methods.rb
23
+ def underscore(camel_cased_word)
24
+ word = camel_cased_word.to_s.gsub('::', '/')
25
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
26
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
27
+ word.tr!("-", "_")
28
+ word.downcase!
29
+ word
30
+ end
31
+
21
32
  def pwd(*path_parts)
22
33
 
23
- root_folder =if ENV['BUNDLE_GEMFILE']
24
- ENV['BUNDLE_GEMFILE'].split(File::Separator)[0..-2].join(File::Separator)
25
- else
26
- Dir.pwd.to_s
27
- end
34
+ root_folder = if ENV['BUNDLE_GEMFILE']
35
+ ENV['BUNDLE_GEMFILE'].split(File::Separator)[0..-2].join(File::Separator)
36
+ else
37
+ Dir.pwd.to_s
38
+ end
28
39
 
29
- return File.join(root_folder,*path_parts)
40
+ return File.join(root_folder, *path_parts)
30
41
 
31
42
  end
32
43
 
@@ -39,7 +50,22 @@ module Rack::App::Utils
39
50
 
40
51
  def join(*url_path_parts)
41
52
  url_path_parts = [url_path_parts].flatten.compact
42
- File.join(*url_path_parts).gsub(File::Separator,'/').sub(/^\/?(.*)$/,'/\1')
53
+ File.join(*url_path_parts).gsub(File::Separator, '/').sub(/^\/?(.*)$/, '/\1')
54
+ end
55
+
56
+ def expand_path(file_path)
57
+ case file_path
58
+
59
+ when /^\.\//
60
+ File.expand_path(File.join(File.dirname(caller[1]),file_path))
61
+
62
+ when /^[^\/]/
63
+ File.join(caller[1].split(/\.(?:rb|ru)/)[0],file_path)
64
+
65
+ when /^\//
66
+ pwd(file_path)
67
+
68
+ end
43
69
  end
44
70
 
45
71
  end
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.21.0
4
+ version: 0.22.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-18 00:00:00.000000000 Z
12
+ date: 2016-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler