Class: BFS::Blob
- Inherits:
-
Object
- Object
- BFS::Blob
- Defined in:
- lib/bfs/blob.rb
Overview
Blobs are references to single blob objects within a bucket.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.open(url) ⇒ Object
Behaves like new, but accepts an optional block.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the underlying bucket connection.
-
#create(**opts, &block) ⇒ Object
Creates the blob and opens it for writing.
-
#info(**opts) ⇒ Object
Info returns the blob info.
-
#initialize(url) ⇒ Blob
constructor
A new instance of Blob.
-
#mv(dst, **opts) ⇒ Object
Moves blob to dst.
-
#open(**opts, &block) ⇒ Object
Opens the blob for reading.
-
#read(**opts) ⇒ Object
Shortcut method to read the contents of the blob.
-
#rm(**opts) ⇒ Object
Deletes the blob.
-
#write(data, **opts) ⇒ Object
Shortcut method to write data to blob.
Constructor Details
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/bfs/blob.rb', line 4 def path @path end |
Class Method Details
.open(url) ⇒ Object
Behaves like new, but accepts an optional block. If a block is given, blobs are automatically closed after the block is yielded.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/bfs/blob.rb', line 8 def self.open(url) blob = new(url) return blob unless block_given? begin yield blob ensure blob.close end end |
Instance Method Details
#close ⇒ Object
Closes the underlying bucket connection.
71 72 73 |
# File 'lib/bfs/blob.rb', line 71 def close @bucket.close end |
#create(**opts, &block) ⇒ Object
Creates the blob and opens it for writing. If a block is passed the writer is automatically committed in the end. If no block is passed, you must manually call #commit to persist the result.
38 39 40 |
# File 'lib/bfs/blob.rb', line 38 def create(**opts, &block) @bucket.create(path, **opts, &block) end |
#info(**opts) ⇒ Object
Info returns the blob info.
30 31 32 |
# File 'lib/bfs/blob.rb', line 30 def info(**opts) @bucket.info(path, **opts) end |
#mv(dst, **opts) ⇒ Object
Moves blob to dst.
64 65 66 67 68 |
# File 'lib/bfs/blob.rb', line 64 def mv(dst, **opts) dst = BFS.norm_path(dst) @bucket.mv(path, dst, **opts) @path = dst end |
#open(**opts, &block) ⇒ Object
Opens the blob for reading. May raise BFS::FileNotFound.
44 45 46 |
# File 'lib/bfs/blob.rb', line 44 def open(**opts, &block) @bucket.open(path, **opts, &block) end |
#read(**opts) ⇒ Object
Shortcut method to read the contents of the blob.
54 55 56 |
# File 'lib/bfs/blob.rb', line 54 def read(**opts) self.open(**opts, &:read) end |
#rm(**opts) ⇒ Object
Deletes the blob.
49 50 51 |
# File 'lib/bfs/blob.rb', line 49 def rm(**opts) @bucket.rm(path, **opts) end |
#write(data, **opts) ⇒ Object
Shortcut method to write data to blob.
59 60 61 |
# File 'lib/bfs/blob.rb', line 59 def write(data, **opts) create(**opts) {|f| f.write data } end |