Class: Blobby::InMemoryStore::StoredObject

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, key) ⇒ StoredObject

Returns a new instance of StoredObject.



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

def initialize(hash, key)
  @hash = hash
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



33
34
35
# File 'lib/blobby/in_memory_store.rb', line 33

def key
  @key
end

Instance Method Details

#deleteObject



60
61
62
# File 'lib/blobby/in_memory_store.rb', line 60

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

#exists?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/blobby/in_memory_store.rb', line 35

def exists?
  @hash.key?(key)
end

#readObject



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

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

#write(content) ⇒ Object



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

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