Class: Blobby::InMemoryStore::StoredObject
- Inherits:
-
Object
- Object
- Blobby::InMemoryStore::StoredObject
- Defined in:
- lib/blobby/in_memory_store.rb
Overview
Represents an object in the store.
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #delete ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(hash, key) ⇒ StoredObject
constructor
A new instance of StoredObject.
- #read ⇒ Object
- #write(content) ⇒ Object
Constructor Details
#initialize(hash, key) ⇒ StoredObject
Returns a new instance of StoredObject.
31 32 33 34 |
# File 'lib/blobby/in_memory_store.rb', line 31 def initialize(hash, key) @hash = hash @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
36 37 38 |
# File 'lib/blobby/in_memory_store.rb', line 36 def key @key end |
Instance Method Details
#delete ⇒ Object
63 64 65 |
# File 'lib/blobby/in_memory_store.rb', line 63 def delete !@hash.delete(key).nil? end |
#exists? ⇒ Boolean
38 39 40 |
# File 'lib/blobby/in_memory_store.rb', line 38 def exists? @hash.key?(key) end |
#read ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/blobby/in_memory_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/in_memory_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 |