rack-app 7.6.1 → 7.7.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
  SHA256:
3
- metadata.gz: 9d79b70dcb9b2e40f6f72d744393137ac491c60e5d8d60580c780c2ed22b1450
4
- data.tar.gz: c49619a0f6b1b369312efd415aa46e8464a649609fcc7b2520fc2ee31046d397
3
+ metadata.gz: bf6acb7c4c89bd038387d214bd7379ade393a3f0b48088f4b7542b6a0c6f05ca
4
+ data.tar.gz: e084eaa3c611498a98bbdb7cb1a8ccbcdc81cc893e1c08848a515db4b9e536f1
5
5
  SHA512:
6
- metadata.gz: 673c644050ef4bcd62cda1144d5078a149e9f13770ec4a0f5855b5659c0b50f025d84fc25f405c16c24194effeb0d65b1bc1bc1f90b8615f3f611cadd085d162
7
- data.tar.gz: 2891119e70ad873a642e1b6d19c921292376be152fe2e08ae175310916ae2d8ee028d5a346e85501c7663c66782d9e37ee6108efdade49feb11fca296c469a7e
6
+ metadata.gz: '09f143bdb3a084226e0f51f9f8c471dff28b06ab99f4f52c0895abd3541673152ef3949f34711a5eb67fc53ce1544c0bfd0acf6d000b30cf803c5b28f96ce1c1'
7
+ data.tar.gz: 6667a98608f80d53984ec9147373e370edecec9b5b525b74c3ff0c354f0843ea685deb2b96b57cae354039f56b1d1ab8104ae20bb1cf884bfba98c36b741c537
data/README.md CHANGED
@@ -33,9 +33,8 @@ when rack provides a finalized support for http2.
33
33
  If you have an issue, I weekly check the issues tab,
34
34
  answer and reply, or implement a fix for it.
35
35
 
36
- Since the framework, the only dependency is the `rack` gem,
37
- I don't have to update the code base,
38
- because there are no integration problems.
36
+ Since the framework's only dependency is the `rack` gem,
37
+ I don't have to update the code base to often.
39
38
 
40
39
  Cheers and Happy Coding!
41
40
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.6.1
1
+ 7.7.0
@@ -1,10 +1,24 @@
1
1
  class Rack::App::FileServer
2
+ attr_accessor :relative_file_paths
2
3
 
3
- def initialize(root_folder)
4
- require 'rack/file'
4
+ def self.serve_file(env, file_path)
5
+ dir_path = File.dirname(file_path)
6
+ basename = File.basename(file_path)
7
+ file_server = new(dir_path, map_relative_file_paths: false)
8
+ env = env.dup
9
+ env[::Rack::App::Constants::ENV::REQUEST_METHOD] = 'GET'
10
+ env[::Rack::App::Constants::ENV::PATH_INFO] = basename
11
+ file_server.call(env)
12
+ end
13
+
14
+ def initialize(root_folder, opts = {})
5
15
  @root_folder = root_folder
6
- @relative_file_paths = Dir.glob(File.join(@root_folder, '**', '*')).map { |file_path| file_path.sub(@root_folder, '') }.sort_by { |str| str.length }.reverse
16
+ @relative_file_paths = []
7
17
  @rack_file_server = ::Rack::File.new(@root_folder, {})
18
+
19
+ if map_relative_file_paths?(opts)
20
+ map_relative_paths!
21
+ end
8
22
  end
9
23
 
10
24
  def call(env)
@@ -12,7 +26,7 @@ class Rack::App::FileServer
12
26
 
13
27
  @relative_file_paths.each do |relative_file_path|
14
28
  if path_info =~ /#{Regexp.escape(relative_file_path)}$/
15
- env[::Rack::App::Constants::ENV::PATH_INFO]= relative_file_path
29
+ env[::Rack::App::Constants::ENV::PATH_INFO] = relative_file_path
16
30
  break
17
31
  end
18
32
  end
@@ -20,19 +34,31 @@ class Rack::App::FileServer
20
34
  @rack_file_server.call(env)
21
35
  end
22
36
 
23
- def self.serve_file(env, file_path)
24
- file_server = self.new(File.dirname(file_path))
25
- env = env.dup
26
- env[::Rack::App::Constants::ENV::REQUEST_METHOD]= 'GET'
27
- env[::Rack::App::Constants::ENV::PATH_INFO]= file_path
28
- file_server.call(env)
37
+ protected
38
+
39
+ def map_relative_file_paths?(opts = {})
40
+ unless opts.key?(:map_relative_file_paths)
41
+ return true
42
+ end
43
+
44
+ opts[:map_relative_file_paths]
29
45
  end
30
46
 
31
- protected
47
+ def opts_set_defaults(opts)
48
+ unless opts.key?(:map_relative_file_paths)
49
+ opts[:map_relative_file_paths] = true
50
+ end
51
+ end
52
+
53
+ def map_relative_paths!
54
+ @relative_file_paths = Dir.glob(File.join(@root_folder, '**', '*'))
55
+ .map { |file_path| file_path.sub(@root_folder, '') }
56
+ .sort_by { |str| str.length }
57
+ .reverse
58
+ end
32
59
 
33
60
  def clean_path_info(env)
34
61
  path_info = ::Rack::Utils.unescape(env[::Rack::App::Constants::ENV::PATH_INFO])
35
62
  ::Rack::Utils.clean_path_info(path_info)
36
63
  end
37
-
38
64
  end
@@ -1,10 +1,10 @@
1
1
  module Rack::App::InstanceMethods::ServeFile
2
2
 
3
3
  def serve_file(file_path)
4
- raw_rack_resp = Rack::App::FileServer.serve_file(request.env, file_path)
5
- response.status = raw_rack_resp[0]
6
- response.headers.merge!(raw_rack_resp[1])
7
- response.body = raw_rack_resp[2]
4
+ rack_resp = Rack::App::FileServer.serve_file(request.env, file_path)
5
+ response.status = rack_resp[0]
6
+ response.headers.merge!(rack_resp[1])
7
+ response.body = rack_resp[2]
8
8
  finish!
9
9
  end
10
10
 
@@ -2,11 +2,11 @@ module Rack::App::Payload::Parser::Builder::Formats
2
2
  extend(self)
3
3
 
4
4
  JSON_CONTENT_TYPES = [
5
- 'application/json',
6
- 'application/x-javascript',
7
- 'text/javascript',
8
- 'text/x-javascript',
9
- 'text/x-json'
5
+ 'application/json',
6
+ 'application/x-javascript',
7
+ 'text/javascript',
8
+ 'text/x-javascript',
9
+ 'text/x-json'
10
10
  ].freeze
11
11
 
12
12
  JSON_PARSER = proc do |io|
@@ -28,9 +28,9 @@ module Rack::App::Payload::Parser::Builder::Formats
28
28
  end
29
29
 
30
30
  JSON_STREAM_CONTENT_TYPES = [
31
- 'application/jsonstream',
32
- 'application/stream+json',
33
- 'application/x-json-stream'
31
+ 'application/jsonstream',
32
+ 'application/stream+json',
33
+ 'application/x-json-stream'
34
34
  ].freeze
35
35
 
36
36
  JSON_STREAM_PARSER = proc do |io|
@@ -62,8 +62,8 @@ module Rack::App::Payload::Parser::Builder::Formats
62
62
  # end
63
63
 
64
64
  FORM_CONTENT_TYPES = [
65
- 'application/x-www-form-urlencoded',
66
- # 'multipart/form-data'
65
+ 'application/x-www-form-urlencoded',
66
+ # 'multipart/form-data'
67
67
  ].freeze
68
68
 
69
69
  FORM_SEP_CHAR = '&'.freeze
@@ -76,7 +76,7 @@ module Rack::App::Payload::Parser::Builder::Formats
76
76
  lambda do |form|
77
77
  ::Rack::Utils.parse_nested_query(form, FORM_SEP_CHAR)
78
78
  end
79
- end
79
+ end
80
80
 
81
81
  NULL_END_CHAR = /#{"\u0000"}$/
82
82
 
@@ -102,7 +102,7 @@ module Rack::App::Payload::Parser::Builder::Formats
102
102
  last_name = form_name
103
103
  unless respond_to?(form_name)
104
104
  raise(NotImplementedError, "unknown formatter: #{last_name}")
105
- end
105
+ end
106
106
  __send__ form_name, builder
107
107
  end
108
108
  end
@@ -46,8 +46,8 @@ module Rack::App::SingletonMethods::Mounting
46
46
  nil
47
47
  end
48
48
 
49
- def serve_files_from(file_path, options={})
50
- file_server = Rack::App::FileServer.new(Rack::App::Utils.expand_path(file_path))
49
+ def serve_files_from(dir_path, options={})
50
+ file_server = Rack::App::FileServer.new(Rack::App::Utils.expand_path(dir_path))
51
51
  request_path = Rack::App::Utils.join(options[:to], Rack::App::Constants::PATH::MOUNT_POINT)
52
52
  add_route(::Rack::App::Constants::HTTP::METHOD::ANY, request_path, file_server)
53
53
  nil
@@ -3,8 +3,8 @@ module Rack::App::Streamer::Scheduler::Null
3
3
  extend(self)
4
4
 
5
5
  def schedule(*)
6
- yield
7
- end
6
+ yield
7
+ end
8
8
 
9
9
  def defer(*)
10
10
  yield
@@ -21,9 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.license = 'Apache License 2.0'
22
22
 
23
23
  spec.add_development_dependency 'bundler'
24
- spec.add_development_dependency 'rake', '10.4.2'
25
24
  spec.add_development_dependency 'rspec'
26
-
27
25
  spec.add_dependency 'rack'
28
26
 
29
27
  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: 7.6.1
4
+ version: 7.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-21 00:00:00.000000000 Z
11
+ date: 2020-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '='
32
- - !ruby/object:Gem::Version
33
- version: 10.4.2
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '='
39
- - !ruby/object:Gem::Version
40
- version: 10.4.2
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -211,7 +197,7 @@ homepage: http://www.rack-app.com/
211
197
  licenses:
212
198
  - Apache License 2.0
213
199
  metadata: {}
214
- post_install_message:
200
+ post_install_message:
215
201
  rdoc_options: []
216
202
  require_paths:
217
203
  - lib
@@ -227,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
213
  version: '0'
228
214
  requirements: []
229
215
  rubygems_version: 3.0.3
230
- signing_key:
216
+ signing_key:
231
217
  specification_version: 4
232
218
  summary: Minimalist rack application interface building framework.
233
219
  test_files: []