A Rails key value store for models
Latest commit 76aef97 Dec 28, 2015 @deanpcmad deanpcmad committed with adamcooke added gem info to readme
Failed to load latest commit information.
lib/nifty bump version to 1.0.3 Sep 7, 2014
.gitignore initial commit Sep 28, 2013
README.md added gem info to readme Jan 4, 2016
nifty-key-value-store.gemspec initial commit Sep 28, 2013


The Nifty Key Value Store

If you want to create a quick key/value store in your application where the values relate to an existing model, this is very helpful.

Add the gem to the Gemfile

gem "nifty-key-value-store", require: "nifty/key_value_store"

You'll need to create the database table and then, once added, you can specify what objects you want to store.

$ rails generate nifty:key_value_store:migration
$ rake db:migrate
class Person < ActiveRecord::Base
  key_value_store :settings
  key_value_store :other_settings

person = Person.new
person.settings             = {:colour => 'red', :fruit => 'apple'}
person.other_settings_json  = "{"hello":"world"}"

person = Person.find(person.id)
person.settings         #=> {'colour' => 'red', 'fruit' => 'apple'}
person.settings_json    #=> "{'color':'red', 'fruit':'apple'}"

A few points to note about this:

  • All values are stored as strings in the database
  • All keys are stored as strings and returned as strings in their hash