Class: Blobby::FilesystemStore::StoredObject

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/blobby/filesystem_store.rb

Overview

Represents an object in the store.

Instance Method Summary collapse

Constructor Details

#initialize(path, umask) ⇒ StoredObject

Returns a new instance of StoredObject.



48
49
50
51
# File 'lib/blobby/filesystem_store.rb', line 48

def initialize(path, umask)
  @path = path
  @umask = umask
end

Instance Method Details

#deleteObject



83
84
85
86
87
88
# File 'lib/blobby/filesystem_store.rb', line 83

def delete
  FileUtils.rm(@path)
  true
rescue Errno::ENOENT
  false
end

#readObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/blobby/filesystem_store.rb', line 57

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



72
73
74
75
76
77
78
79
80
81
# File 'lib/blobby/filesystem_store.rb', line 72

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