From 44aab4d65931175628b1aa6b1fe3e4152b64e6a9 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 7 Jul 2017 17:13:02 +0200 Subject: It is an engine (because of tasks) not a railtie --- lib/active_storage.rb | 2 +- lib/active_storage/engine.rb | 56 +++++++++++++++++++++++++++++++++++++++++++ lib/active_storage/railtie.rb | 56 ------------------------------------------- 3 files changed, 57 insertions(+), 57 deletions(-) create mode 100644 lib/active_storage/engine.rb delete mode 100644 lib/active_storage/railtie.rb (limited to 'lib') diff --git a/lib/active_storage.rb b/lib/active_storage.rb index f72fe0d017..8b867f0145 100644 --- a/lib/active_storage.rb +++ b/lib/active_storage.rb @@ -1,5 +1,5 @@ require "active_record" -require "active_storage/railtie" if defined?(Rails) +require "active_storage/engine" if defined?(Rails) module ActiveStorage extend ActiveSupport::Autoload diff --git a/lib/active_storage/engine.rb b/lib/active_storage/engine.rb new file mode 100644 index 0000000000..3512be0468 --- /dev/null +++ b/lib/active_storage/engine.rb @@ -0,0 +1,56 @@ +require "rails/engine" + +module ActiveStorage + class Engine < Rails::Engine # :nodoc: + config.active_storage = ActiveSupport::OrderedOptions.new + + config.eager_load_namespaces << ActiveStorage + + initializer "active_storage.routes" do + require "active_storage/disk_controller" + + config.after_initialize do |app| + app.routes.prepend do + get "/rails/blobs/:encoded_key" => "active_storage/disk#show", as: :rails_disk_blob + end + end + end + + initializer "active_storage.attached" do + require "active_storage/attached" + + ActiveSupport.on_load(:active_record) do + extend ActiveStorage::Attached::Macros + end + end + + config.after_initialize do |app| + config_choice = app.config.active_storage.service + config_file = Pathname.new(Rails.root.join("config/storage_services.yml")) + + if config_choice + raise("Couldn't find Active Storage configuration in #{config_file}") unless config_file.exist? + + begin + require "yaml" + require "erb" + configs = YAML.load(ERB.new(config_file.read).result) || {} + + if service_configuration = configs[config_choice.to_s].symbolize_keys + service_name = service_configuration.delete(:service) + + ActiveStorage::Blob.service = ActiveStorage::Service.configure(service_name, service_configuration) + else + raise "Couldn't configure Active Storage as #{config_choice} was not found in #{config_file}" + end + 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}" + rescue => e + raise e, "Cannot load `Rails.config.active_storage.service`:\n#{e.message}", e.backtrace + end + end + end + end +end diff --git a/lib/active_storage/railtie.rb b/lib/active_storage/railtie.rb deleted file mode 100644 index 76894c2e16..0000000000 --- a/lib/active_storage/railtie.rb +++ /dev/null @@ -1,56 +0,0 @@ -require "rails/railtie" - -module ActiveStorage - class Engine < Rails::Engine # :nodoc: - config.active_storage = ActiveSupport::OrderedOptions.new - - config.eager_load_namespaces << ActiveStorage - - initializer "active_storage.routes" do - require "active_storage/disk_controller" - - config.after_initialize do |app| - app.routes.prepend do - get "/rails/blobs/:encoded_key" => "active_storage/disk#show", as: :rails_disk_blob - end - end - end - - initializer "active_storage.attached" do - require "active_storage/attached" - - ActiveSupport.on_load(:active_record) do - extend ActiveStorage::Attached::Macros - end - end - - config.after_initialize do |app| - config_choice = app.config.active_storage.service - config_file = Pathname.new(Rails.root.join("config/storage_services.yml")) - - if config_choice - raise("Couldn't find Active Storage configuration in #{config_file}") unless config_file.exist? - - begin - require "yaml" - require "erb" - configs = YAML.load(ERB.new(config_file.read).result) || {} - - if service_configuration = configs[config_choice.to_s].symbolize_keys - service_name = service_configuration.delete(:service) - - ActiveStorage::Blob.service = ActiveStorage::Service.configure(service_name, service_configuration) - else - raise "Couldn't configure Active Storage as #{config_choice} was not found in #{config_file}" - end - 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}" - rescue => e - raise e, "Cannot load `Rails.config.active_storage.service`:\n#{e.message}", e.backtrace - end - end - end - end -end -- cgit v1.2.3