Created
June 16, 2015 21:27
-
-
Save ybur-yug/03da94f54f8df7244c3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Gkv | |
class Database | |
attr_accessor :items | |
def initialize | |
`git init` | |
@items = {} | |
end | |
def set(key, value) | |
@items[key] = hash_object(value) | |
#@items[key] = [hash_object(value)] | |
end | |
def get(key) | |
cat_file(@items[key]) | |
#cat_file(@items[key.to_s]).strip! | |
end | |
def hash_object(data) | |
write_tmpfile(data) | |
hash = `git hash-object -w tmp.txt`.strip! | |
File.delete('tmp.txt') | |
hash | |
end | |
def write_tmpfile(data) | |
f = File.open("tmp.txt", "w+") | |
f.write(data.to_s) | |
f.close | |
end | |
def cat_file(hash) | |
`git cat-file -p #{hash}` | |
end | |
end | |
end | |
db = Gkv::Database.new | |
db.set("Apples", "10") | |
puts db.get("Apples") | |
# => 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment