Class: SimpleStore::Memory

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_store/memory.rb

Direct Known Subclasses

Disk

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bucketObject (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_allObject



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_sObject



23
24
25
# File 'lib/simple_store/memory.rb', line 23

def to_s
  data.inspect
end