Class: Blobby::AbstractStore::StoredObject Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/blobby/abstract_store.rb

Overview

This class is abstract.

A handle to an object in the BLOB-store.

Instance Method Summary collapse

Instance Method Details

#deleteObject



61
62
63
# File 'lib/blobby/abstract_store.rb', line 61

def delete
  !@hash.delete(key).nil?
end

#exists?Boolean

Check for existence.

Returns:

  • (Boolean)

    true if the object exists



28
29
30
# File 'lib/blobby/abstract_store.rb', line 28

def exists?
  false
end

#readString? #read {|chunk| ... } ⇒ void

Overloads:

  • #readString?

    Read BLOB data.

    Returns:

    • (String)

      data if the object exists

    • (nil)

      if the object doesn’t exist

  • #read {|chunk| ... } ⇒ void

    This method returns an undefined value.

    Stream BLOB data in chunks.

    Yields:

    • (chunk)

      each chunk of data



40
41
42
43
44
45
46
47
48
# File 'lib/blobby/abstract_store.rb', line 40

def read
  content = @hash[key]
  if block_given?
    yield content
    nil
  else
    content
  end
end

#write(content) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/blobby/abstract_store.rb', line 50

def write(content)
  if content.respond_to?(:read)
    content = content.read
  else
    content = content.to_str.dup
  end
  content = content.force_encoding("BINARY") if content.respond_to?(:force_encoding)
  @hash[key] = content
  nil
end