-
Notifications
You must be signed in to change notification settings - Fork 12
Home
Toystore is an object mapper for anything that can read, write, and delete by a provided key. For more on the history of Toystore, you can read Data Modeling in Performant Systems.
gem install toystore
Toystore is built on top of Active Model and Adapter (wiki). Adapter is a simple gem for adapting a particular client to one simple API (similar to Ruby's hash API). Adapter actually ships with a memory adapter. To use this with Toystore, you can do the following:
require 'adapter/memory'
require 'toystore'
class User
include Toy::Store
adapter :memory, {}
attribute :name, String
end
Simply include Toy::Store and then declare where you would like to store your data by passing the adapter name and an the client to the store method. From there you can declare your attributes and do anything else you want. There are several examples included with the source.
If you change your mind and would like to store your data in Mongo, instead of just in memory, you can simply change the adapter:
require 'adapter/mongo'
require 'toystore'
class User
include Toy::Store
adapter :mongo, Mongo::Connection.new.db('adapter')['testing']
attribute :name, String
end
Pretty cool, eh?
- Rails 3, Sinatra, etc. No Rails 2 (because it uses Active Model).
- Ruby 1.9.3
For any questions or help regarding ToyStore or Adapter, hit up the google group.