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
Search Repo:
Added pulling of a key's bit index
Brennan Dunn (author)
Tue Mar 25 09:10:02 -0700 2008
commit  7c1c0e3e07aa706f422a4ec3aeb3fe1104f4d080
tree    621b1b836c89c6dac0a91fdcea80b9f70a8aaf95
parent  4c16d0b45cddf3e02848be3f45adcebaf35ea058
0
...
40
41
42
43
 
44
45
46
47
...
52
53
54
55
 
56
 
 
 
 
57
58
59
...
40
41
42
 
43
44
45
46
47
...
52
53
54
 
55
56
57
58
59
60
61
62
63
0
@@ -40,7 +40,7 @@
0
   
0
 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.
0
 
0
-Setting a preference:
0
+Setting a key:
0
   ...individually
0
   @user.prefs[:delete_user] = true
0
     
0
0
@@ -52,8 +52,12 @@
0
    @user.prefs[:create_user] = 'yes'
0
 
0
 
0
-Fetching a preference:
0
+Fetching a key:
0
   @user.prefs[:change_theme] => false
0
+
0
+
0
+Getting the index of a key:
0
+ @user.prefs.index(:delete_user) => 4
0
   
0
 
0
 Enumerable...
...
122
123
124
 
 
 
 
 
125
126
127
...
122
123
124
125
126
127
128
129
130
131
132
0
@@ -122,6 +122,11 @@
0
       update_permissions
0
     end
0
     
0
+ def index(key)
0
+ idx, hsh = lookup(key)
0
+ idx
0
+ end
0
+
0
     # used for mass assignment of preferences, such as a hash from params
0
     def store(prefs)
0
       prefs.each do |key, value|
...
53
54
55
 
 
 
 
56
...
53
54
55
56
57
58
59
60
0
@@ -53,5 +53,9 @@
0
     end
0
   end
0
   
0
+ def test_lookup_index_of_key
0
+ assert_equal 4, @person.prefs.index(:delete_user)
0
+ end
0
+
0
 end

Comments

    No one has commented yet.