public
Description: Allows the storage of a number of boolean fields with just one table column
Homepage: http://www.brennandunn.com
Clone URL: git://github.com/brennandunn/preference_fu.git
Wrote README
Brennan Dunn (author)
Mon Mar 24 12:16:36 -0700 2008
commit  00967b8928183c68d6c6e6df356a0b9d4f564616
tree    f451cebacefb3237cdc71a389b42bd719ff9dbe0
parent  d9933c19f7fa232d30efa4d6c583bdbbe5584e85
0
...
1
2
3
4
 
 
 
5
 
 
6
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
9
10
 
 
 
 
11
 
12
13
 
...
1
2
3
 
4
5
6
7
8
9
10
 
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 
67
68
69
70
71
72
73
 
74
0
@@ -1,13 +1,74 @@
0
 PreferenceFu
0
 ============
0
 
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
 
0
+Because the values are stored within a bit vector, a virtually unlimited number of preferences can be created without additional
0
+migrations.
0
 
0
-Example
0
+Feel free to email me with any suggestions or problems.
0
+
0
+Blog: http://www.brennandunn.com
0
+Email address: me@brennandunn.com
0
+
0
+
0
+Setup
0
+=====
0
+
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
+
0
+ def preferences_column
0
+ 'other_column'
0
+ end
0
+
0
+
0
+Examples
0
+========
0
+
0
+Using PreferenceFu is very simple.
0
+
0
+ class User < ActiveRecord::Base
0
+
0
+ has_preferences :send_email, :change_theme, :delete_user, :create_user
0
+
0
+ set_default_preference :send_email, true
0
+
0
+ end
0
+
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
+
0
+Setting a preference:
0
+ ...individually
0
+ @user.preferences[:delete_user] = true
0
+
0
+ ...mass assignment (useful with the params hash)
0
+ @user.preferences = {:delete_user => true, :create_user => true}
0
+
0
+
0
+Fetching a preference:
0
+ @user.preferences[:change_theme] => false
0
+
0
+
0
+Enumerable...
0
+ @user.preferences.size => 4
0
+
0
+ @user.preferences.each do |key, value|
0
+ puts "#{key} is set to #{value}"
0
+ end
0
+
0
+
0
+Warning
0
 =======
0
 
0
-Example goes here.
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
 
0
+
0
 
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.