diff options
author | George Claghorn <george@basecamp.com> | 2017-11-23 19:48:25 -0500 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2017-11-23 19:48:25 -0500 |
commit | fbb12910bdf256bbe2a95909fff114243d75424d (patch) | |
tree | b1fed0462c96a0bd46b0203ceeea2b3ae1f9834f /activestorage/lib | |
parent | a7d7277f947dcbe31870af9f03a42d56d2b60fcc (diff) | |
download | rails-fbb12910bdf256bbe2a95909fff114243d75424d.tar.gz rails-fbb12910bdf256bbe2a95909fff114243d75424d.tar.bz2 rails-fbb12910bdf256bbe2a95909fff114243d75424d.zip |
Avoid connecting to GCS during app boot
Diffstat (limited to 'activestorage/lib')
-rw-r--r-- | activestorage/lib/active_storage/service/gcs_service.rb | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/activestorage/lib/active_storage/service/gcs_service.rb b/activestorage/lib/active_storage/service/gcs_service.rb index b4ffeeeb8a..be6ddf32a0 100644 --- a/activestorage/lib/active_storage/service/gcs_service.rb +++ b/activestorage/lib/active_storage/service/gcs_service.rb @@ -7,11 +7,8 @@ module ActiveStorage # Wraps the Google Cloud Storage as an Active Storage service. See ActiveStorage::Service for the generic API # documentation that applies to all services. class Service::GCSService < Service - attr_reader :client, :bucket - - def initialize(project:, keyfile:, bucket:, **options) - @client = Google::Cloud::Storage.new(project: project, keyfile: keyfile, **options) - @bucket = @client.bucket(bucket) + def initialize(**config) + @config = config end def upload(key, io, checksum: nil) @@ -85,8 +82,18 @@ module ActiveStorage end private + attr_reader :config + def file_for(key) bucket.file(key, skip_lookup: true) end + + def bucket + @bucket ||= client.bucket(config.fetch(:bucket)) + end + + def client + @client ||= Google::Cloud::Storage.new(config.except(:bucket)) + end end end |