Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defer Active Storage service configuration until use
- Loading branch information
1 parent
986d3bf
commit 709cee9
Showing
7 changed files
with
61 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveStorage | ||
class Service::Registry #:nodoc: | ||
def initialize(configurations) | ||
@configurations = configurations.deep_symbolize_keys | ||
@services = {} | ||
end | ||
|
||
def fetch(name) | ||
services.fetch(name.to_sym) do |key| | ||
if configurations.include?(key) | ||
services[key] = configurator.build(key) | ||
else | ||
if block_given? | ||
yield key | ||
else | ||
raise KeyError, "Missing configuration for the #{key} Active Storage service. " \ | ||
"Configurations available for the #{configurations.keys.to_sentence} services." | ||
end | ||
end | ||
end | ||
end | ||
|
||
private | ||
attr_reader :configurations, :services | ||
|
||
def configurator | ||
@configurator ||= ActiveStorage::Service::Configurator.new(configurations) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters