class Blobby::GCSStore
A BLOB store backed by Google Cloud Storage.
Attributes
bucket_name[R]
gcs_options[R]
Public Class Methods
from_uri(uri)
click to toggle source
# File lib/blobby/gcs_store.rb, line 13 def self.from_uri(uri) uri = URI(uri) raise ArgumentError, "invalid GCS address: #{uri}" unless uri.scheme == 'gs' bucket_name = uri.host prefix = uri.path.sub(%r{\A/}, '').sub(%r{/\Z}, '') raise ArgumentError, 'no bucket specified' if bucket_name.nil? store = new(bucket_name) store = KeyTransformingStore.new(store) { |key| prefix + '/' + key } unless prefix.empty? store end
new(bucket_name, gcs_options: {})
click to toggle source
# File lib/blobby/gcs_store.rb, line 26 def initialize(bucket_name, gcs_options: {}) @bucket_name = bucket_name @gcs_options = gcs_options end
Public Instance Methods
[](key)
click to toggle source
# File lib/blobby/gcs_store.rb, line 35 def [](key) KeyConstraint.must_allow!(key) StoredObject.new(bucket, key) end
available?()
click to toggle source
# File lib/blobby/gcs_store.rb, line 31 def available? !!bucket&.exists? end
Private Instance Methods
bucket()
click to toggle source
# File lib/blobby/gcs_store.rb, line 96 def bucket @bucket ||= gcs_client.bucket(bucket_name, skip_lookup: true) end
gcs_client()
click to toggle source
# File lib/blobby/gcs_store.rb, line 100 def gcs_client @gcs_client ||= Google::Cloud::Storage.new(gcs_options) end