Class: Blobby::GCSStore

Inherits:
Object
  • Object
show all
Defined in:
lib/blobby/gcs_store.rb

Overview

A BLOB store backed by Google Cloud Storage.

Defined Under Namespace

Classes: StoredObject

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket_name, gcs_options: {}) ⇒ GCSStore

Returns a new instance of GCSStore.



26
27
28
29
# File 'lib/blobby/gcs_store.rb', line 26

def initialize(bucket_name, gcs_options: {})
  @bucket_name = bucket_name
  @gcs_options = gcs_options
end

Class Method Details

.from_uri(uri) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
# 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

Instance Method Details

#[](key) ⇒ Object



35
36
37
38
# File 'lib/blobby/gcs_store.rb', line 35

def [](key)
  KeyConstraint.must_allow!(key)
  StoredObject.new(bucket, key)
end

#available?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/blobby/gcs_store.rb', line 31

def available?
  !!bucket&.exists?
end