Class: Blobby::FilesystemStore::StoredObject

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

Instance Method Summary collapse

Constructor Details

#initialize(path, umask) ⇒ StoredObject

Returns a new instance of StoredObject.



40
41
42
43
# File 'lib/blobby/filesystem_store.rb', line 40

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

Instance Method Details

#deleteObject



75
76
77
78
79
# File 'lib/blobby/filesystem_store.rb', line 75

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

#readObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/blobby/filesystem_store.rb', line 49

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



64
65
66
67
68
69
70
71
72
73
# File 'lib/blobby/filesystem_store.rb', line 64

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