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



63
64
65
# File 'lib/blobby/abstract_store.rb', line 63

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

#exists?Boolean

Check for existence.

Returns:

  • (Boolean)

    true if the object exists



30
31
32
# File 'lib/blobby/abstract_store.rb', line 30

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



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

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

#write(content) ⇒ Object



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

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