0
-Introduction goes here.
0
+This plugin, greatly inspired by Jim Morris' blog post (http://blog.wolfman.com/articles/2007/08/07/bit-vector-preferences)
0
+aims to make it easy and flexible to store boolean preferences for an ActiveRecord model. This can be also used as a very
0
+quick way to setup an ACL.
0
+Because the values are stored within a bit vector, a virtually unlimited number of preferences can be created without additional
0
+Feel free to email me with any suggestions or problems.
0
+Blog: http://www.brennandunn.com
0
+Email address: me@brennandunn.com
0
+Simply add an integer column to each table of the database that requires preferences. By default, the column used is
0
+'preferences', but by defining a method called preferences_column this can be modified.
0
+ def preferences_column
0
+Using PreferenceFu is very simple.
0
+ class User < ActiveRecord::Base
0
+ has_preferences :send_email, :change_theme, :delete_user, :create_user
0
+ set_default_preference :send_email, true
0
+For new AR objects, all preference options will be set to false. This can be overwritten using set_default_preference. I
0
+really recommend you read the 'Warning' section below.
0
+ @user.preferences[:delete_user] = true
0
+ ...mass assignment (useful with the params hash)
0
+ @user.preferences = {:delete_user => true, :create_user => true}
0
+ @user.preferences[:change_theme] => false
0
+ @user.preferences.size => 4
0
+ @user.preferences.each do |key, value|
0
+ puts "#{key} is set to #{value}"
0
+This works by taking the index of the splat supplied in has_preferences as the power of two, summing all values, and storing
0
+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
0
+third by 4, etc. Once you start using PreferenceFu in production, add new options to the *end* of the splat. At the moment,
0
+there's no safe way to delete a preference item at the moment. Any advice is welcome!
0
-Copyright (c) 2008 [name of plugin creator], released under the MIT license
0
+Copyright (c) 2008 Brennan Dunn, released under the MIT license
Comments
No one has commented yet.