diff --git a/lib/bucket_store/gcs.rb b/lib/bucket_store/gcs.rb index e4b97fe..88c387b 100644 --- a/lib/bucket_store/gcs.rb +++ b/lib/bucket_store/gcs.rb @@ -3,17 +3,21 @@ require "stringio" require "uri" -require "google/cloud/storage" - module BucketStore class Gcs DEFAULT_TIMEOUT_SECONDS = 30 + def self.load_client_library + @load_client_library ||= require "google/cloud/storage" + end + def self.build(timeout_seconds = DEFAULT_TIMEOUT_SECONDS) - Gcs.new(timeout_seconds) + new(timeout_seconds) end def initialize(timeout_seconds) + self.class.load_client_library + # Ruby's GCS library does not natively support setting up a simulator, but it allows # for a specific endpoint to be passed down which has the same effect. The simulator # needs to be special cased as in that case we want to bypass authentication, diff --git a/lib/bucket_store/s3.rb b/lib/bucket_store/s3.rb index 89b5ef3..5be5919 100644 --- a/lib/bucket_store/s3.rb +++ b/lib/bucket_store/s3.rb @@ -2,18 +2,22 @@ require "uri" -require "aws-sdk-s3" - module BucketStore class S3 DEFAULT_TIMEOUT_SECONDS = 30 + def self.load_client_library + @load_client_library ||= require "aws-sdk-s3" + end + def self.build(open_timeout_seconds = DEFAULT_TIMEOUT_SECONDS, read_timeout_seconds = DEFAULT_TIMEOUT_SECONDS) - S3.new(open_timeout_seconds, read_timeout_seconds) + new(open_timeout_seconds, read_timeout_seconds) end def initialize(open_timeout_seconds, read_timeout_seconds) + self.class.load_client_library + @storage = Aws::S3::Client.new( http_open_timeout: open_timeout_seconds, http_read_timeout: read_timeout_seconds, diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6ae9b4d..9470f69 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require "logger" require "bucket_store" RSpec.configure do |config|