Project

persist

0.01
No commit activity in last 3 years
No release in over 3 years
The Persist gem makes it really, really simple to persist Ruby objects to disk.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

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.

Usage

Example in irb or Pry:

require 'persist'

store = Persist.new
store[: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'

store = Persist.new
store[:pie]
  #=> ["Key Lime", "Strawberry Rhubarb", "Blackberry Cobbler"]

Transactions

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

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

Helper Methods

Look up table keys:

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

store.key? :pie
  #=> true

store.key? :cake
  #=> false

Delete tables:

store.delete :pie
  #=> nil

File Store Path

Set the path to the persistant store file upon initialization:

store = Persist.new "../.db.pstore"
store.path
  #=> "../.db.pstore"

The default path is ".db.pstore" if one is not otherwise specified:

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

Installation

Install the gem from the command line:

gem install persist

Or add the gem to your app's Gemfile and bundle install:

gem 'persist'

Supported Platforms

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

  1. Ruby 1.9 or higher.
  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. 🍰