Name
PStore — Simple object-oriented database class
Synopsis
PStore
is a simple object-oriented database
class that provides almost arbitrary data persistence (using
Marshal
) and transaction.
Required Library
require ‘pstore’
Class Method
PStore::new(
path
)
Creates a database object. Data is stored in a file specified by
path
.
Instance Methods
p
.transaction {|
ps
|
...
}
Starts a transaction (a series of database operations). Access to the contents of the database can be achieved only through this transaction method.
p
[
name
]
Retrieves an object stored in the database under the key name.
p
[
name
]=
obj
Stores
obj
in the database under the key name. When the transaction is completed, all objects accessed reflexively byobj
(seeMarshal
in Section 3.4) are saved in a file.p
.root?(
name
)
Returns
true
if the key name exists in the database.p
.commit
Completes the transaction. When this method is called, the block passed to the transaction method is executed, and changes to the database are written to the database file.
p
.abort
Aborts the transaction. When this method is called, the execution of the block passed to the transaction method is terminated, and changes made to database objects during the transaction aren’t written to the database file.
Get Ruby in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.