Class: Blobby::FilesystemStore::StoredObject
- Inherits:
-
Object
- Object
- Blobby::FilesystemStore::StoredObject
- Extended by:
- Forwardable
- Defined in:
- lib/blobby/filesystem_store.rb
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(path, umask) ⇒ StoredObject
constructor
A new instance of StoredObject.
- #read ⇒ Object
- #write(content) ⇒ Object
Constructor Details
#initialize(path, umask) ⇒ StoredObject
Returns a new instance of StoredObject.
45 46 47 48 |
# File 'lib/blobby/filesystem_store.rb', line 45 def initialize(path, umask) @path = path @umask = umask end |
Instance Method Details
#delete ⇒ Object
80 81 82 83 84 85 |
# File 'lib/blobby/filesystem_store.rb', line 80 def delete FileUtils.rm(@path) true rescue Errno::ENOENT false end |
#read ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/blobby/filesystem_store.rb', line 54 def read @path.open("rb") do |io| if block_given? while (chunk = io.read(512)) yield chunk end nil else io.read end end rescue Errno::ENOENT nil end |
#write(content) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/blobby/filesystem_store.rb', line 69 def write(content) atomic_create(@path) do |out| if content.respond_to?(:read) FileUtils.copy_stream(content, out) else out << content end end nil end |