Class: SimpleStore::Memory
- Inherits:
-
Object
- Object
- SimpleStore::Memory
- Defined in:
- lib/simple_store/memory.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
Instance Method Summary collapse
- #destroy_all ⇒ Object
- #get(key) ⇒ Object
-
#initialize(bucket) ⇒ Memory
constructor
A new instance of Memory.
- #put(attributes) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(bucket) ⇒ Memory
Returns a new instance of Memory.
5 6 7 8 |
# File 'lib/simple_store/memory.rb', line 5 def initialize(bucket) @bucket = bucket data[bucket] ||= {} end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
3 4 5 |
# File 'lib/simple_store/memory.rb', line 3 def bucket @bucket end |
Instance Method Details
#destroy_all ⇒ Object
19 20 21 |
# File 'lib/simple_store/memory.rb', line 19 def destroy_all data[bucket] = {} end |
#get(key) ⇒ Object
15 16 17 |
# File 'lib/simple_store/memory.rb', line 15 def get(key) data[bucket].fetch(key) { raise SimpleStore::RecordNotFound, "Record not found with key #{key}"} end |
#put(attributes) ⇒ Object
10 11 12 13 |
# File 'lib/simple_store/memory.rb', line 10 def put(attributes) key = find_key(attributes) data[bucket][key] = attributes end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/simple_store/memory.rb', line 23 def to_s data.inspect end |