lib/active_storage/engine.rb in activestorage-6.0.6.1 vs lib/active_storage/engine.rb in activestorage-6.1.0.rc1
- old
+ new
@@ -12,21 +12,23 @@
require "active_storage/previewer/video_previewer"
require "active_storage/analyzer/image_analyzer"
require "active_storage/analyzer/video_analyzer"
+require "active_storage/service/registry"
+
require "active_storage/reflection"
module ActiveStorage
class Engine < Rails::Engine # :nodoc:
isolate_namespace ActiveStorage
config.active_storage = ActiveSupport::OrderedOptions.new
config.active_storage.previewers = [ ActiveStorage::Previewer::PopplerPDFPreviewer, ActiveStorage::Previewer::MuPDFPreviewer, ActiveStorage::Previewer::VideoPreviewer ]
config.active_storage.analyzers = [ ActiveStorage::Analyzer::ImageAnalyzer, ActiveStorage::Analyzer::VideoAnalyzer ]
config.active_storage.paths = ActiveSupport::OrderedOptions.new
- config.active_storage.queues = ActiveSupport::OrderedOptions.new
+ config.active_storage.queues = ActiveSupport::InheritableOptions.new(mirror: :active_storage_mirror)
config.active_storage.variable_content_types = %w(
image/png
image/gif
image/jpg
@@ -34,12 +36,20 @@
image/pjpeg
image/tiff
image/bmp
image/vnd.adobe.photoshop
image/vnd.microsoft.icon
+ image/webp
)
+ config.active_storage.web_image_content_types = %w(
+ image/png
+ image/jpeg
+ image/jpg
+ image/gif
+ )
+
config.active_storage.content_types_to_serve_as_binary = %w(
text/html
text/javascript
image/svg+xml
application/postscript
@@ -61,44 +71,32 @@
image/vnd.adobe.photoshop
image/vnd.microsoft.icon
application/pdf
)
- default_unsupported_image_processing_arguments = %w(
- -debug
- -display
- -distribute-cache
- -help
- -path
- -print
- -set
- -verbose
- -version
- -write
- -write-mask
- )
-
config.eager_load_namespaces << ActiveStorage
initializer "active_storage.configs" do
config.after_initialize do |app|
ActiveStorage.logger = app.config.active_storage.logger || Rails.logger
ActiveStorage.variant_processor = app.config.active_storage.variant_processor || :mini_magick
ActiveStorage.previewers = app.config.active_storage.previewers || []
ActiveStorage.analyzers = app.config.active_storage.analyzers || []
ActiveStorage.paths = app.config.active_storage.paths || {}
ActiveStorage.routes_prefix = app.config.active_storage.routes_prefix || "/rails/active_storage"
+ ActiveStorage.draw_routes = app.config.active_storage.draw_routes != false
+ ActiveStorage.resolve_model_to_route = app.config.active_storage.resolve_model_to_route || :rails_storage_redirect
- ActiveStorage.supported_image_processing_methods = app.config.active_storage.supported_image_processing_methods || []
- ActiveStorage.unsupported_image_processing_arguments = app.config.active_storage.unsupported_image_processing_arguments || default_unsupported_image_processing_arguments
ActiveStorage.variable_content_types = app.config.active_storage.variable_content_types || []
+ ActiveStorage.web_image_content_types = app.config.active_storage.web_image_content_types || []
ActiveStorage.content_types_to_serve_as_binary = app.config.active_storage.content_types_to_serve_as_binary || []
ActiveStorage.service_urls_expire_in = app.config.active_storage.service_urls_expire_in || 5.minutes
ActiveStorage.content_types_allowed_inline = app.config.active_storage.content_types_allowed_inline || []
ActiveStorage.binary_content_type = app.config.active_storage.binary_content_type || "application/octet-stream"
ActiveStorage.replace_on_assign_to_many = app.config.active_storage.replace_on_assign_to_many || false
+ ActiveStorage.track_variants = app.config.active_storage.track_variants || false
end
end
initializer "active_storage.attached" do
require "active_storage/attached"
@@ -114,45 +112,29 @@
end
end
initializer "active_storage.services" do
ActiveSupport.on_load(:active_storage_blob) do
- if config_choice = Rails.configuration.active_storage.service
- configs = Rails.configuration.active_storage.service_configurations ||= begin
- config_file = Pathname.new(Rails.root.join("config/storage.yml"))
+ configs = Rails.configuration.active_storage.service_configurations ||=
+ begin
+ config_file = Rails.root.join("config/storage/#{Rails.env}.yml")
+ config_file = Rails.root.join("config/storage.yml") unless config_file.exist?
raise("Couldn't find Active Storage configuration in #{config_file}") unless config_file.exist?
- require "yaml"
- require "erb"
-
- YAML.load(ERB.new(config_file.read).result) || {}
- rescue Psych::SyntaxError => e
- raise "YAML syntax error occurred while parsing #{config_file}. " \
- "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
- "Error: #{e.message}"
+ ActiveSupport::ConfigurationFile.parse(config_file)
end
- ActiveStorage::Blob.service =
- begin
- ActiveStorage::Service.configure config_choice, configs
- rescue => e
- raise e, "Cannot load `Rails.config.active_storage.service`:\n#{e.message}", e.backtrace
- end
+ ActiveStorage::Blob.services = ActiveStorage::Service::Registry.new(configs)
+
+ if config_choice = Rails.configuration.active_storage.service
+ ActiveStorage::Blob.service = ActiveStorage::Blob.services.fetch(config_choice)
end
end
end
initializer "active_storage.queues" do
config.after_initialize do |app|
- if queue = app.config.active_storage.queue
- ActiveSupport::Deprecation.warn \
- "config.active_storage.queue is deprecated and will be removed in Rails 6.1. " \
- "Set config.active_storage.queues.purge and config.active_storage.queues.analysis instead."
-
- ActiveStorage.queues = { purge: queue, analysis: queue }
- else
- ActiveStorage.queues = app.config.active_storage.queues || {}
- end
+ ActiveStorage.queues = app.config.active_storage.queues || {}
end
end
initializer "active_storage.reflection" do
ActiveSupport.on_load(:active_record) do