Created
June 16, 2015 20:19
-
-
Save ybur-yug/d0a8129a57448bf182c0 to your computer and use it in GitHub Desktop.
This file contains 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] = value | |
end | |
def get(key) | |
cat_file(@items[key.to_s]).strip! | |
end | |
private | |
def hash_object(data) | |
`echo "#{data.to_s}" | git hash-object -w --stdin`.strip! | |
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") | |
db.set("Apples", "5") | |
puts db.get("Apples") | |
# problem is that in IRB if I just run the exact pieces from hash_object it works...perplexed but also brain dead today | |
bobby@devbox:~/code/gkv$ ruby lib/gkv.rb | |
# =>fatal: Not a valid object name 10 | |
# =>fatal: Not a valid object name 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting the same for 2.2.x, and an odd error that's probably my fault on 2.1.5.