I am getting my feet wet with Ruby object persistence.
I decided to look at PStore first, then move to Yaml, as it was
mentioned in my Peter C. Ruby book.
I know that PStore is typically used for program config value
persistence, and that the transaction keyword fairly much ensures the
integrity of the operation, and a binary pstore file is created. Beyond
that, I am pretty lost. I searched the forum here, and googled pstore,
but it was not that helpful.
What I wanted to do, as a start, was to save my entire object “fdb1”,
which is an instance of class “Faunadb”. Then, after closing Ruby, “copy
back” the saved object, and list object variable contents, to
demonstrate persistence conclusively. It seems to work, but I have
The code to save the object, that I have cobbled together, without
understanding it, is:
<start of “copy to” code>
##code above here to populate the object fdb1
store[:this] ||= Faunadb.new("")
store[:this] = fdb1
<end of “copy to” code>
I can see the created file, and cat it though it is binary.
And the code to restore it, is:
<start of “copy back” code>
fdb1.listobs #to prove the data is back.
<end of “copy back” code>
In this line of code “store[:this] ||= Faunadb.new(”")" , what is the
double pipe equal sign doing? Does it just indicate that the :this
symbol points to the new Faunadb instance? Why is the double pipe thingy
not used on the “copy back” code fragment? Would I use the symbol to
just keep track of what is stored? I know :this is pretty goofy.
In this line of code fdb1=store[:this] from the restore, I noticed
that it is necessary to have the same symbol :this, in this code
fragment, as it was in the prior fragment, because I get an error
otherwise. Is this correct?
My environment is ruby 1.8.7 on Linux.
Any tips appreciated.
Thanks in advance.