Persist

Build Status

The Persist gem makes it really, really simple to persist Ruby objects to disk. Persist uses Ruby's PStore class to serialize Ruby objects with Marshal and transactionally save them for retrieval later.

Installation

Install the gem from the command line: gem install persist

Usage

Example in irb or Pry:

require 'persist'
Persist[:pie] = ['Key Lime', 'Strawberry Rhubarb', 'Blackberry Cobbler']
  # => ["Key Lime", "Strawberry Rhubarb", "Blackberry Cobbler"]

You can now exit irb or Pry and your Ruby objects are still there:

require 'persist'
Persist[:pie]
  #=> ["Key Lime", "Strawberry Rhubarb", "Blackberry Cobbler"]

Transactions

Transactions succeed or fail together to ensure that data is not left in a transitory state:

Persist.transaction do |db|
  db[:ice_cream] = ['chocolate', 'vanilla']
  db.delete :pie
end

Helper Methods

Tables are treated as Hash keys:

Persist.keys
  #=> [:pie, :ice_cream]

Persist.key? :pie
  #=> true

Persist.key? :cake
  #=> false

Easily delete tables:

Persist.delete :pie
  #=> nil

Check the location of the persistant file on disk:

Persist.path
  #=> ".db.pstore"

Additional documentation in the code.

Supported Platforms

Persist takes advantage of PStore's ultra_safe attribute, which requires:

  1. Ruby 1.9+ compatibility (tested on Ruby 2.0.0, 1.9.3, JRuby and Rubinius).
  2. A POSIX compliant platform (such as OS X, GNU/Linux or a BSD).

Contributing

  1. Fork it
  2. Commit changes (git commit -am 'did something')
  3. Submit a Pull Request
  4. :cake: