This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
commit e2ca7f0fa788cb221b208a428abc747a14e82fe7
tree 92c490bb86c58dbade803ded53c5f925f3fdeeac
parent c47a0693b9915db24ea1901260a99ab050dbd1a9
tree 92c490bb86c58dbade803ded53c5f925f3fdeeac
parent c47a0693b9915db24ea1901260a99ab050dbd1a9
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Mon Mar 24 11:29:47 -0700 2008 | [Brennan Dunn] |
| |
README | Tue Mar 25 09:10:02 -0700 2008 | [Brennan Dunn] |
| |
Rakefile | Mon Mar 24 11:29:47 -0700 2008 | [Brennan Dunn] |
| |
init.rb | Mon Mar 24 11:29:47 -0700 2008 | [Brennan Dunn] |
| |
install.rb | Mon Mar 24 11:29:47 -0700 2008 | [Brennan Dunn] |
| |
lib/ | Tue May 20 00:45:48 -0700 2008 | [dynamix] |
| |
tasks/ | Mon Mar 24 11:29:47 -0700 2008 | [Brennan Dunn] |
| |
test/ | Tue Mar 25 09:10:02 -0700 2008 | [Brennan Dunn] |
| |
uninstall.rb | Mon Mar 24 11:29:47 -0700 2008 | [Brennan Dunn] |
README
PreferenceFu ============ This plugin, greatly inspired by Jim Morris' blog post (http://blog.wolfman.com/articles/2007/08/07/bit-vector-preferences), aims to make it easy and flexible to store boolean preferences for an ActiveRecord model. This can be also used as a very quick way to setup an ACL. Because the values are stored within a bit vector, a virtually unlimited number of preferences can be created without additional migrations. Feel free to email me with any suggestions or problems. Blog: http://www.brennandunn.com Email address: me@brennandunn.com Setup ===== Simply add an integer column to each table of the database that requires preferences. By default, the column used is 'preferences', but by defining a method called preferences_column this can be modified. def preferences_column 'other_column' end Your migration should probably look something like this: add_column :people, :preferences, :integer Examples ======== Using PreferenceFu is very simple. class User < ActiveRecord::Base has_preferences :send_email, :change_theme, :delete_user, :create_user set_default_preference :send_email, true end For new AR objects, all preference options will be set to false. This can be overwritten using set_default_preference. I really recommend you read the 'Warning' section below. Setting a key: ...individually @user.prefs[:delete_user] = true ...mass assignment (useful with the params hash) @user.prefs = {:delete_user => true, :create_user => true} Setting an option as true doesn't necessarily need to be done with the Boolean true - in fact, the Fixnum 1, and strings '1', 'y' and 'yes' are all valid. This is particularly helpful for checkbox form posts. @user.prefs[:create_user] = 'yes' Fetching a key: @user.prefs[:change_theme] => false Getting the index of a key: @user.prefs.index(:delete_user) => 4 Enumerable... @user.prefs.size => 4 @user.prefs.each do |key, value| puts "#{key} is set to #{value}" end Warning ======= This works by taking the index of the splat supplied in has_preferences as the power of two, summing all values, and storing the sum in the preferences column. Because of this, the first item in the splat will be identified by 1, the second by 2, the third by 4, etc. Once you start using PreferenceFu in production, add new options to the *end* of the splat. At the moment, there's no safe way to delete a preference item at the moment. Any advice is welcome! Copyright (c) 2008 Brennan Dunn, released under the MIT license





