1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activestorage/lib/active_storage/service/configurator.rb
Rafael Mendonça França 18707ab17f
Standardize nodoc comments
2021-07-29 21:18:07 +00:00

36 lines
1 KiB
Ruby

# frozen_string_literal: true
module ActiveStorage
class Service::Configurator # :nodoc:
attr_reader :configurations
def self.build(service_name, configurations)
new(configurations).build(service_name)
end
def initialize(configurations)
@configurations = configurations.deep_symbolize_keys
end
def build(service_name)
config = config_for(service_name.to_sym)
resolve(config.fetch(:service)).build(
**config, configurator: self, name: service_name
)
end
private
def config_for(name)
configurations.fetch name do
raise "Missing configuration for the #{name.inspect} Active Storage service. Configurations available for #{configurations.keys.inspect}"
end
end
def resolve(class_name)
require "active_storage/service/#{class_name.to_s.underscore}_service"
ActiveStorage::Service.const_get(:"#{class_name.camelize}Service")
rescue LoadError
raise "Missing service adapter for #{class_name.inspect}"
end
end
end