Send the right exception for missing entry.
parent
5d662e4225
commit
835537ed83
|
@ -1,3 +1,7 @@
|
||||||
|
require "file_utils"
|
||||||
|
require "json"
|
||||||
|
|
||||||
|
require "./dodb.cr"
|
||||||
|
|
||||||
#class Hash(K,V)
|
#class Hash(K,V)
|
||||||
# def reverse
|
# def reverse
|
||||||
|
@ -37,6 +41,7 @@ class DODB::DataBase::Cached(V)
|
||||||
self[index] = item
|
self[index] = item
|
||||||
self.last_index = index
|
self.last_index = index
|
||||||
@data[self.last_index] = item
|
@data[self.last_index] = item
|
||||||
|
self.last_index
|
||||||
end
|
end
|
||||||
|
|
||||||
# Getting data from the hash in RAM.
|
# Getting data from the hash in RAM.
|
||||||
|
@ -49,7 +54,7 @@ class DODB::DataBase::Cached(V)
|
||||||
def [](key : Int32) : V
|
def [](key : Int32) : V
|
||||||
# raise MissingEntry.new(key) unless ::File.exists? file_path key
|
# raise MissingEntry.new(key) unless ::File.exists? file_path key
|
||||||
# read file_path key
|
# read file_path key
|
||||||
@data[key]
|
@data[key] rescue raise MissingEntry.new(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
def []=(index : Int32, value : V)
|
def []=(index : Int32, value : V)
|
||||||
|
@ -301,4 +306,3 @@ class DODB::DataBase::Cached(V)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue