You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
479 B
28 lines
479 B
2 years ago
|
module Minitest::Thesis
|
||
|
class DirectoryDb
|
||
|
def initialize(dir)
|
||
|
@dir = dir
|
||
|
Dir.mkdir(@dir)
|
||
|
rescue SystemCallError => e
|
||
|
raise unless e.errno == Errno::EEXIST::Errno
|
||
|
end
|
||
|
|
||
|
def [](key)
|
||
|
f = file(key)
|
||
|
return nil unless File.exist?(f)
|
||
|
|
||
|
File.read(f)
|
||
|
end
|
||
|
|
||
|
def []=(key, value)
|
||
|
File.write(file(key), value)
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def file(key)
|
||
|
File.join(@dir, Digest::SHA1.hexdigest(key)[0...10])
|
||
|
end
|
||
|
end
|
||
|
end
|