1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

removes require_dependency calls in ActiveStorage::Blob

The less we depend on require_dependency, the better.
This commit is contained in:
Xavier Noria 2020-04-30 00:27:19 +02:00
parent 92d03850f3
commit c7c3abe03b

View file

@ -15,15 +15,24 @@
# update a blob's metadata on a subsequent pass, but you should not update the key or change the uploaded file.
# If you need to create a derivative or otherwise change the blob, simply create a new blob and purge the old one.
class ActiveStorage::Blob < ActiveRecord::Base
unless Rails.autoloaders.zeitwerk_enabled?
require_dependency "active_storage/blob/analyzable"
require_dependency "active_storage/blob/identifiable"
require_dependency "active_storage/blob/representable"
end
include Analyzable
include Identifiable
include Representable
# We use constant paths in the following include calls to avoid a gotcha of
# classic mode: If the parent application defines a top-level Analyzable, for
# example, and ActiveStorage::Blob::Analyzable is not yet loaded, a bare
#
# include Analyzable
#
# would resolve to the top-level one, const_missing would not be triggered,
# and therefore ActiveStorage::Blob::Analyzable would not be autoloaded.
#
# By using qualified names, we ensure const_missing is invoked if needed.
# Please, note that Ruby 2.5 or newer is required, so Object is not checked
# when looking up the ancestors of ActiveStorage::Blob.
#
# Zeitwerk mode does not have this gotcha. If we ever drop classic mode, this
# can be simplified, bare constant names would just work.
include ActiveStorage::Blob::Analyzable
include ActiveStorage::Blob::Identifiable
include ActiveStorage::Blob::Representable
self.table_name = "active_storage_blobs"