Skip to content

Instantly share code, notes, and snippets.

@ybur-yug
Created June 16, 2015 20:19
Show Gist options
  • Save ybur-yug/d0a8129a57448bf182c0 to your computer and use it in GitHub Desktop.
Save ybur-yug/d0a8129a57448bf182c0 to your computer and use it in GitHub Desktop.
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
@Ch4s3
Copy link

Ch4s3 commented Jun 16, 2015

I'm getting the same for 2.2.x, and an odd error that's probably my fault on 2.1.5.

@Ch4s3
Copy link

Ch4s3 commented Jun 16, 2015

You aren't calling hash_objet...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment