rack-app 7.6.5 → 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: f181500774143b5c53a11d4dd9f06a4f3782808226b2ad840fd5af9fe3dcff96
4
- data.tar.gz: 4059d1bd01e8f36ec6a0d46b41bdfd524e002789125e0e51b3d4a716bd5c35aa
3
+ metadata.gz: bf6acb7c4c89bd038387d214bd7379ade393a3f0b48088f4b7542b6a0c6f05ca
4
+ data.tar.gz: e084eaa3c611498a98bbdb7cb1a8ccbcdc81cc893e1c08848a515db4b9e536f1
5
5
  SHA512:
6
- metadata.gz: 7a209cb4d5cfb40f161a15bcce3f049b16558f71aef1597d8a02a721f410774ea6b3e6752ba73cb3f8711fd59163fa904fd5fbde635b5b6ff7b949abf6ad7843
7
- data.tar.gz: 590c2a8ec95a1a6f1d8b9610f76d87d197cfa449efe97ca2a5c3a3a4bc13f383ad0620ca82891058e20c0b6e90ec99812d58a6c81f163bec960e61964aa26442
6
+ metadata.gz: '09f143bdb3a084226e0f51f9f8c471dff28b06ab99f4f52c0895abd3541673152ef3949f34711a5eb67fc53ce1544c0bfd0acf6d000b30cf803c5b28f96ce1c1'
7
+ data.tar.gz: 6667a98608f80d53984ec9147373e370edecec9b5b525b74c3ff0c354f0843ea685deb2b96b57cae354039f56b1d1ab8104ae20bb1cf884bfba98c36b741c537
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.6.5
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
@@ -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
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: 7.6.5
4
+ version: 7.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi