Class: Bosh::Blobstore::BaseClient
- Defined in:
- lib/blobstore_client/base.rb
Direct Known Subclasses
DavBlobstoreClient, LocalClient, RetryableBlobstoreClient, S3BlobstoreClient, Sha1VerifiableBlobstoreClient, SimpleBlobstoreClient
Constant Summary
Constants inherited from Client
Client::PROVIDER_NAMES, Client::VERSION
Instance Method Summary collapse
-
#create(contents, id = nil) ⇒ String
Saves a file or a string to the blobstore.
- #delete(oid) ⇒ void
- #exists?(oid) ⇒ Boolean
-
#get(id, file = nil, options = {}) ⇒ String
Get an object from the blobstore.
-
#initialize(options) ⇒ BaseClient
constructor
A new instance of BaseClient.
Methods inherited from Client
Constructor Details
#initialize(options) ⇒ BaseClient
Returns a new instance of BaseClient.
11 12 13 |
# File 'lib/blobstore_client/base.rb', line 11 def initialize() @options = Bosh::Common.symbolize_keys() end |
Instance Method Details
#create(contents, id = nil) ⇒ String #create(file, id = nil) ⇒ String
Saves a file or a string to the blobstore. if it is a String, it writes it to a temp file then calls create_file() with the (temp) file
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/blobstore_client/base.rb', line 25 def create(contents, id = nil) if contents.kind_of?(File) create_file(id, contents) else temp_path do |path| File.open(path, 'w') do |file| file.write(contents) end return create_file(id, File.open(path, 'r')) end end rescue BlobstoreError => e raise e rescue Exception => e raise BlobstoreError, sprintf('Failed to create object, underlying error: %s %s', e.inspect, e.backtrace.join("\n")) end |
#delete(oid) ⇒ void
This method returns an undefined value.
68 69 70 |
# File 'lib/blobstore_client/base.rb', line 68 def delete(oid) delete_object(oid) end |
#exists?(oid) ⇒ Boolean
73 74 75 |
# File 'lib/blobstore_client/base.rb', line 73 def exists?(oid) object_exists?(oid) end |
#get(id, file = nil, options = {}) ⇒ String
Get an object from the blobstore.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/blobstore_client/base.rb', line 48 def get(id, file = nil, = {}) if file get_file(id, file) file.flush else result = nil temp_path do |path| File.open(path, 'w') { |f| get_file(id, f) } result = File.open(path, 'r') { |f| f.read } end result end rescue BlobstoreError => e raise e rescue Exception => e raise BlobstoreError, sprintf('Failed to fetch object, underlying error: %s %s', e.inspect, e.backtrace.join("\n")) end |