Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2674 from sonalkr132/rails-6-0-default
Enable zeitwerk autoloader
- Loading branch information
Showing
12 changed files
with
99 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# ignore rake tasks because don't need to autoload them | ||
Rails.autoloaders.main.ignore(Rails.root.join("lib/tasks")) | ||
|
||
# does not require autoload. ignore SqsWorker to supress following: | ||
# expected file lib/shoryuken/sqs_worker.rb to define constant Shoryuken::SqsWorker | ||
Rails.autoloaders.main.ignore(Rails.root.join("lib/shoryuken")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Gemcutter::Middleware | ||
class Hostess < Rack::Static | ||
def initialize(app, options = {}) | ||
options[:root] = RubygemFs.instance.base_dir | ||
|
||
options[:urls] = %w[ | ||
/specs.4.8.gz | ||
/latest_specs.4.8.gz | ||
/prerelease_specs.4.8.gz | ||
/quick/rubygems-update-1.3.6.gemspec.rz | ||
/yaml.Z | ||
/yaml.z | ||
/Marshal.4.8.Z | ||
/quick/index.rz | ||
/quick/latest_index.rz | ||
/yaml | ||
/Marshal.4.8 | ||
/specs.4.8 | ||
/latest_specs.4.8 | ||
/prerelease_specs.4.8 | ||
/quick/index | ||
/quick/latest_index | ||
] | ||
|
||
super(app, options) | ||
end | ||
|
||
def can_serve(path) | ||
super(path) || gem_download_path(path) || path =~ %r{/quick/Marshal\.4\.8/.*\.gemspec.rz} | ||
end | ||
|
||
def gem_download_path(path) | ||
Regexp.last_match(1) if path =~ %r{/gems/(.*)\.gem} | ||
end | ||
|
||
def call(env) | ||
path = env["PATH_INFO"] | ||
|
||
return [302, { "Location" => "/gems/#{Regexp.last_match(1)}.gem" }, []] if path =~ %r{/downloads/(.*)\.gem} | ||
|
||
download_path = gem_download_path(path) | ||
name = Version.rubygem_name_for(download_path) if download_path | ||
if name | ||
GemDownload.transaction do | ||
GemDownload.bulk_update([[download_path, 1]]) | ||
end | ||
end | ||
super | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Gemcutter::Middleware | ||
class Redirector | ||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
request = Rack::Request.new(env) | ||
|
||
allowed_hosts = [Gemcutter::HOST, "index.rubygems.org", "fastly.rubygems.org", "bundler.rubygems.org"] | ||
|
||
if !allowed_hosts.include?(request.host) && request.path !~ %r{^/api|^/internal} && request.host !~ /docs/ | ||
fake_request = Rack::Request.new(env.merge("HTTP_HOST" => Gemcutter::HOST)) | ||
redirect_to(fake_request.url) | ||
elsif request.path =~ %r{^/(book|chapter|export|read|shelf|syndicate)} && request.host !~ /docs/ | ||
redirect_to("https://docs.rubygems.org#{request.path}") | ||
else | ||
@app.call(env) | ||
end | ||
end | ||
|
||
private | ||
|
||
def redirect_to(url) | ||
[301, { "Location" => url }, []] | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
test/unit/hostess_test.rb → ...unit/gemcutter/middleware/hostess_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/unit/redirector_test.rb → ...t/gemcutter/middleware/redirector_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters