summaryrefslogtreecommitdiff
path: root/lib/rack/static.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-01-27 14:30:11 -0800
committerJeremy Evans <code@jeremyevans.net>2020-01-27 19:30:54 -0800
commitab41dccfe287b7d2589778308cb297eb039e88c6 (patch)
treed3a65fce77c68542ead4b606c0a2dc02e294eeaf /lib/rack/static.rb
parent68dde7b79b30dd1a721eaf503e20ace8e162b980 (diff)
downloadrack-ab41dccfe287b7d2589778308cb297eb039e88c6.tar.gz
Use require_relative and rely on autoload instead of using require
This does a better job of testing the autoloads work, and ensures files are loaded from the current rack directory. Some files required rack.rb, and in those cases I didn't remove the require, just replaced it with require_relative, since the intent is to make sure all of rack is loaded if a file under rack is loaded. This has the potential to break code that does: require 'rack/content_type' Rack::ContentType.new(app) If the rack library itself is never required. This is because the autoloads that rack.rb sets up would not be loaded. I'm not sure if we want to support that, but if so we would want to keep the requires and convert them to require_relative. For core_ext/regexp, move the requires into the if < 2.4 block, so that the file isn't loaded unless it is necessary.
Diffstat (limited to 'lib/rack/static.rb')
-rw-r--r--lib/rack/static.rb7
1 files changed, 1 insertions, 6 deletions
diff --git a/lib/rack/static.rb b/lib/rack/static.rb
index 0338073f..8cb58b2f 100644
--- a/lib/rack/static.rb
+++ b/lib/rack/static.rb
@@ -1,10 +1,5 @@
# frozen_string_literal: true
-require "rack/files"
-require "rack/utils"
-
-require_relative 'core_ext/regexp'
-
module Rack
# The Rack::Static middleware intercepts requests for static files
@@ -91,7 +86,7 @@ module Rack
# ]
#
class Static
- using ::Rack::RegexpExtensions if RUBY_VERSION < '2.4'
+ (require_relative 'core_ext/regexp'; using ::Rack::RegexpExtensions) if RUBY_VERSION < '2.4'
def initialize(app, options = {})
@app = app