From 7c5814c6e0de3d0694debd1d41ebeca038cdd11d Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Sun, 31 Mar 2019 19:23:11 -0400 Subject: [PATCH] Revert "Add ActiveStorage.service_configurations and ActiveStorage.service" This reverts commit 002684e36e813469c3585e193f0698784c88278b. --- .../app/models/active_storage/blob.rb | 2 +- activestorage/lib/active_storage.rb | 28 +++++++---------- activestorage/lib/active_storage/engine.rb | 30 +++++++++---------- activestorage/lib/active_storage/service.rb | 2 +- 4 files changed, 28 insertions(+), 34 deletions(-) diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb index 4da1605448..c9fbafad1f 100644 --- a/activestorage/app/models/active_storage/blob.rb +++ b/activestorage/app/models/active_storage/blob.rb @@ -29,7 +29,7 @@ class ActiveStorage::Blob < ActiveRecord::Base has_secure_token :key store :metadata, accessors: [ :analyzed, :identified ], coder: ActiveRecord::Coders::JSON - class_attribute :service, default: ActiveStorage.service + class_attribute :service has_many :attachments diff --git a/activestorage/lib/active_storage.rb b/activestorage/lib/active_storage.rb index c00c9f8037..5c5da551ae 100644 --- a/activestorage/lib/active_storage.rb +++ b/activestorage/lib/active_storage.rb @@ -41,25 +41,19 @@ module ActiveStorage autoload :Previewer autoload :Analyzer - mattr_accessor :service_configurations, default: {} - mattr_accessor :service - - mattr_accessor :queues, default: {} - mattr_accessor :previewers, default: [] - mattr_accessor :analyzers, default: [] - mattr_accessor :variant_processor, default: :mini_magick - mattr_accessor :paths, default: {} - - mattr_accessor :variable_content_types, default: [] - mattr_accessor :content_types_to_serve_as_binary, default: [] - mattr_accessor :content_types_allowed_inline, default: [] - mattr_accessor :binary_content_type, default: "application/octet-stream" - - mattr_accessor :service_urls_expire_in, default: 5.minutes - mattr_accessor :routes_prefix, default: "/rails/active_storage" - mattr_accessor :logger mattr_accessor :verifier + mattr_accessor :queues, default: {} + mattr_accessor :previewers, default: [] + mattr_accessor :analyzers, default: [] + mattr_accessor :variant_processor, default: :mini_magick + mattr_accessor :paths, default: {} + mattr_accessor :variable_content_types, default: [] + mattr_accessor :content_types_to_serve_as_binary, default: [] + mattr_accessor :content_types_allowed_inline, default: [] + mattr_accessor :binary_content_type, default: "application/octet-stream" + mattr_accessor :service_urls_expire_in, default: 5.minutes + mattr_accessor :routes_prefix, default: "/rails/active_storage" module Transformers extend ActiveSupport::Autoload diff --git a/activestorage/lib/active_storage/engine.rb b/activestorage/lib/active_storage/engine.rb index b27a027f3a..fc75a8f816 100644 --- a/activestorage/lib/active_storage/engine.rb +++ b/activestorage/lib/active_storage/engine.rb @@ -95,25 +95,25 @@ module ActiveStorage end initializer "active_storage.services" do - config.after_initialize do |app| - ActiveStorage.service_configurations = begin - config_file = Pathname.new(Rails.root.join("config/storage.yml")) - raise("Couldn't find Active Storage configuration in #{config_file}") unless config_file.exist? + 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")) + raise("Couldn't find Active Storage configuration in #{config_file}") unless config_file.exist? - require "yaml" - require "erb" + 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}" - end + 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}" + end - if global_service_name = app.config.active_storage.service - ActiveStorage.service = + ActiveStorage::Blob.service = begin - ActiveStorage::Service.configure(global_service_name) + ActiveStorage::Service.configure config_choice, configs rescue => e raise e, "Cannot load `Rails.config.active_storage.service`:\n#{e.message}", e.backtrace end diff --git a/activestorage/lib/active_storage/service.rb b/activestorage/lib/active_storage/service.rb index f0d04153a1..aac1e62e7f 100644 --- a/activestorage/lib/active_storage/service.rb +++ b/activestorage/lib/active_storage/service.rb @@ -45,7 +45,7 @@ module ActiveStorage # Configure an Active Storage service by name from a set of configurations, # typically loaded from a YAML file. The Active Storage engine uses this # to set the global Active Storage service when the app boots. - def configure(service_name, configurations = ActiveStorage.service_configurations) + def configure(service_name, configurations) Configurator.build(service_name, configurations) end