Palsy - Set and forget it

Present ruby core data structures in a manner similar to perl's tie backed by a SQLite database. Intended to be as simple as possible, sacrificing performance and flexibility to do so.

It is not a 1:1 emulation of tie, as ruby cannot support this. What it does do is provide a convincing enough facsimile by emulating the interface, and making it easy to convert to native ruby types when that's not enough.

This library is completely unapologetic with regards to how little it does or how slow it does things.

All writes are fully consistent, which is something SQLite gives us. Reads always hit the database. This allows us to reason more clearly about how our data persists, even in concurrent models where shared state can get very complicated to use.

This was largely written to deal with problems I had to resolve in chef-workflow. If you like the idea but would like something more general or support for your favorite database, check out Moneta which is a little more geared towards having a flexible backend.

Usage Example

Here's an example for dealing with several collections.

require 'palsy'

# only one palsy instance exists in a given ruby process
Palsy.database = 'test.db'
# first arg is table name, second is object name.
# standard datatypes are aggressive indexed and constrained. just because we
# don't care about performance doesn't mean we ignore easy wins.
set_a = Palsy::Set.new('some_sets', 'set_a')
set_b = Palsy::Set.new('some_sets', 'set_b')
set_c = Palsy::Set.new('some_sets', 'set_c')

set_a.add('something')
set_b.add('something_else')
# they are nestable like you'd expect.
set_c.add(set_a)

# enumerable works with collections like you'd expect. the results however are
# not palsy objects, so you cannot expect persistence by transformating them.
# consequently, most bang methods will not work as you expect either.
set_a.group_by(&:length)

# they are not ruby 'Set' objects, they just act like them.
# to get at more esoteric methods you'll need to convert them to the proper
# ruby type.
#
# For example, Set theory operators on Palsy::Set are not first class, you need
# to convert to a ruby Set first. Casting to array, hash and set is something
# we try to support wherever possible.
#
# Below we get the union of set_a and set_b

set_a.to_set | set_b.to_set

Installation

Add this line to your application's Gemfile:

gem 'palsy'

And then execute:

$ bundle

Or install it yourself as:

$ gem install palsy

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Changes to author, license or version information without prior approval will be rejected regardless of other changes.

Author

Erik Hollensbe [email protected]