seriously im blanking so hard on this, check it:
2.2.1 :001 > require 'gkv'
=> true
2.2.1 :002 > db = Gkv::Database.new
=> #<Gkv::Database:0x000000016395d8>
2.2.1 :003 > db.set('test', {key: 'val'})
=> "test"
2.2.1 :004 > db.get('test')
Psych::SyntaxError: (<unknown>): did not find expected node content while parsing a flow node at line 1 column 2
from /home/bobby/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:370:in `parse'
from /home/bobby/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:370:in `parse_stream'
from /home/bobby/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:318:in `parse'
from /home/bobby/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:245:in `load'
from /home/bobby/.rvm/gems/ruby-2.2.1/gems/gkv-0.2.1/lib/gkv/database.rb:21:in `get'
from (irb):4
from /home/bobby/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'
2.2.1 :005 > db.set('test2', "{key: 'val'}")
=> "test2"
2.2.1 :006 > db.get('test2')
=> {"key"=>"val"}
2.2.1 :007 > db.get('test2').class
=> Hash
Using the old hash syntax:
2.2.1 :005 > db.set('a', {:key => 'value'})
=> "a"
2.2.1 :006 > db.get('a')
Psych::SyntaxError: (<unknown>): did not find expected node content while parsing a flow node at line 1 column 2
from /home/bobby/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:370:in `parse'
from /home/bobby/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:370:in `parse_stream'
from /home/bobby/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:318:in `parse'
from /home/bobby/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:245:in `load'
from /home/bobby/.rvm/gems/ruby-2.2.1/gems/gkv-0.2.1/lib/gkv/database.rb:21:in `get'
from (irb):6
from /home/bobby/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'
I'm loading it as strings into YAML's lib:
if we set it as a hash that is a string, it reads out as a hash properly BUT if we input the hash as an actual hash it breaks with that Psych error EVEN THOUGH i coerce all the input to strings from the source:
...
def get(key)
if $ITEMS.keys.include? key
YAML.load(Gkv::GitFunctions.cat_file($ITEMS[key].last))
else
raise KeyError
end
end
def set(key, value)
update_items(key, value.to_s)
key
end
...
and update items:
...
def update_items(key, value)
if $ITEMS.keys.include? key
history = $ITEMS[key]
history << Gkv::GitFunctions.hash_object(value.to_s)
$ITEMS[key] = history
else
$ITEMS[key] = [Gkv::GitFunctions.hash_object(value.to_s)]
end
end
end
...
I think it's a Psych error. I just ran it locally and it works fine... (though it outputs as a string) Here's what I did:
¯\ (ツ)/¯