bitmask_attributes 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. data/.gitignore +2 -1
  2. data/CHANGELOG.rdoc +14 -0
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +18 -11
  5. data/{README.md → README.rdoc} +27 -28
  6. data/Rakefile +137 -0
  7. data/bitmask_attributes.gemspec +1 -3
  8. data/doc/apple-touch-icon.png +0 -0
  9. data/doc/classes/BitmaskAttributes.html +114 -0
  10. data/doc/classes/BitmaskAttributes/ClassMethods.html +205 -0
  11. data/doc/classes/BitmaskAttributes/Definition.html +690 -0
  12. data/doc/classes/BitmaskAttributes/ValueProxy.html +468 -0
  13. data/doc/created.rid +7 -0
  14. data/doc/css/github.css +129 -0
  15. data/doc/css/main.css +326 -0
  16. data/doc/css/panel.css +384 -0
  17. data/doc/css/reset.css +48 -0
  18. data/doc/favicon.ico +0 -0
  19. data/doc/files/CHANGELOG_rdoc.html +67 -0
  20. data/doc/files/README_rdoc.html +224 -0
  21. data/doc/files/lib/bitmask_attributes/definition_rb.html +83 -0
  22. data/doc/files/lib/bitmask_attributes/value_proxy_rb.html +83 -0
  23. data/doc/files/lib/bitmask_attributes/version_rb.html +78 -0
  24. data/doc/files/lib/bitmask_attributes_rb.html +93 -0
  25. data/doc/i/arrows.png +0 -0
  26. data/doc/i/results_bg.png +0 -0
  27. data/doc/i/tree_bg.png +0 -0
  28. data/doc/index.html +13 -0
  29. data/doc/js/highlight.pack.js +1 -0
  30. data/doc/js/jquery-1.3.2.min.js +19 -0
  31. data/doc/js/jquery-effect.js +593 -0
  32. data/doc/js/main.js +24 -0
  33. data/doc/js/navigation.js +142 -0
  34. data/doc/js/search_index.js +1 -0
  35. data/doc/js/searchdoc.js +442 -0
  36. data/doc/js/searcher.js +228 -0
  37. data/doc/panel/index.html +73 -0
  38. data/doc/panel/links.html +18 -0
  39. data/doc/panel/tree.js +1 -0
  40. data/lib/bitmask_attributes/definition.rb +4 -4
  41. data/lib/bitmask_attributes/version.rb +1 -1
  42. metadata +39 -6
@@ -0,0 +1,224 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <title>README.rdoc</title>
7
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
8
+ <link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" />
9
+ <link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" />
10
+ <link rel="stylesheet" href="../css/github.css" type="text/css" media="screen" />
11
+ <script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
12
+ <script src="../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
13
+ <script src="../js/main.js" type="text/javascript" charset="utf-8"></script>
14
+ <script src="../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
15
+
16
+ </head>
17
+
18
+ <body>
19
+ <div class="banner">
20
+
21
+ <h1>
22
+ README.rdoc
23
+ </h1>
24
+ <ul class="files">
25
+ <li>README.rdoc</li>
26
+ <li>Last modified: 2011-11-23 09:32:58 +0000</li>
27
+ </ul>
28
+ </div>
29
+
30
+ <div id="bodyContent">
31
+ <div id="content">
32
+
33
+ <div class="description">
34
+
35
+ <h2 id="label-BitmaskAttributes"><a href="../classes/BitmaskAttributes.html">BitmaskAttributes</a></h2>
36
+
37
+ <p>Transparent manipulation of bitmask attributes for ActiveRecord, based on
38
+ the bitmask-attribute gem, which has been dormant since 2009. This updated
39
+ gem work with Rails 3 and up (including Rails 3.1).</p>
40
+
41
+ <h3 id="label-Installation">Installation</h3>
42
+
43
+ <p>The best way to install is with RubyGems:</p>
44
+
45
+ <pre>$ [sudo] gem install bitmask_attributes</pre>
46
+
47
+ <p>Or better still, just add it to your Gemfile:</p>
48
+
49
+ <pre>gem 'bitmask_attributes'</pre>
50
+
51
+ <h3 id="label-Example">Example</h3>
52
+
53
+ <p>Simply declare an existing integer column as a bitmask with its possible
54
+ values.</p>
55
+
56
+ <pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">User</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
57
+ <span class="ruby-identifier">bitmask</span> :<span class="ruby-identifier">roles</span>, :<span class="ruby-identifier">as</span> =<span class="ruby-operator">&gt;</span> [:<span class="ruby-identifier">writer</span>, :<span class="ruby-identifier">publisher</span>, :<span class="ruby-identifier">editor</span>, :<span class="ruby-identifier">proofreader</span>]
58
+ <span class="ruby-keyword">end</span>
59
+ </pre>
60
+
61
+ <p>You can then modify the column using the declared values without resorting
62
+ to manual bitmasks.</p>
63
+
64
+ <pre class="ruby"><span class="ruby-identifier">user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">create</span>(:<span class="ruby-identifier">name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&quot;Bruce&quot;</span>, :<span class="ruby-identifier">roles</span> =<span class="ruby-operator">&gt;</span> [:<span class="ruby-identifier">publisher</span>, :<span class="ruby-identifier">editor</span>])
65
+ <span class="ruby-identifier">user</span>.<span class="ruby-identifier">roles</span>
66
+ <span class="ruby-comment"># =&gt; [:publisher, :editor]</span>
67
+ <span class="ruby-identifier">user</span>.<span class="ruby-identifier">roles</span> <span class="ruby-operator">&lt;&lt;</span> :<span class="ruby-identifier">writer</span>
68
+ <span class="ruby-identifier">user</span>.<span class="ruby-identifier">roles</span>
69
+ <span class="ruby-comment"># =&gt; [:publisher, :editor, :writer]</span>
70
+ </pre>
71
+
72
+ <p>It’s easy to find out if a record has a given value:</p>
73
+
74
+ <pre class="ruby"><span class="ruby-identifier">user</span>.<span class="ruby-identifier">roles?</span>(:<span class="ruby-identifier">editor</span>)
75
+ <span class="ruby-comment"># =&gt; true</span>
76
+ </pre>
77
+
78
+ <p>You can check for multiple values (uses an `and` boolean):</p>
79
+
80
+ <pre class="ruby"><span class="ruby-identifier">user</span>.<span class="ruby-identifier">roles?</span>(:<span class="ruby-identifier">editor</span>, :<span class="ruby-identifier">publisher</span>)
81
+ <span class="ruby-comment"># =&gt; true</span>
82
+ <span class="ruby-identifier">user</span>.<span class="ruby-identifier">roles?</span>(:<span class="ruby-identifier">editor</span>, :<span class="ruby-identifier">proofreader</span>)
83
+ <span class="ruby-comment"># =&gt; false</span>
84
+ </pre>
85
+
86
+ <p>Or, just check if any values are present:</p>
87
+
88
+ <pre class="ruby"><span class="ruby-identifier">user</span>.<span class="ruby-identifier">roles?</span>
89
+ <span class="ruby-comment"># =&gt; true</span>
90
+ </pre>
91
+
92
+ <p>You can get the list of values for any given attribute:</p>
93
+
94
+ <pre class="ruby"><span class="ruby-constant">User</span>.<span class="ruby-identifier">values_for_roles</span>
95
+ <span class="ruby-comment"># =&gt; [:writer, :publisher, :editor, :proofreader]</span>
96
+ </pre>
97
+
98
+ <h3 id="label-Named+Scopes">Named Scopes</h3>
99
+
100
+ <p>A couple useful named scopes are also generated when you use `bitmask`:</p>
101
+
102
+ <pre class="ruby"><span class="ruby-constant">User</span>.<span class="ruby-identifier">with_roles</span>
103
+ <span class="ruby-comment"># =&gt; (all users with roles)</span>
104
+ <span class="ruby-constant">User</span>.<span class="ruby-identifier">with_roles</span>(:<span class="ruby-identifier">editor</span>)
105
+ <span class="ruby-comment"># =&gt; (all editors)</span>
106
+ <span class="ruby-constant">User</span>.<span class="ruby-identifier">with_roles</span>(:<span class="ruby-identifier">editor</span>, :<span class="ruby-identifier">writer</span>)
107
+ <span class="ruby-comment"># =&gt; (all users who are BOTH editors and writers)</span>
108
+ <span class="ruby-constant">User</span>.<span class="ruby-identifier">with_any_roles</span>(:<span class="ruby-identifier">editor</span>, :<span class="ruby-identifier">writer</span>)
109
+ <span class="ruby-comment"># =&gt; (all users who are editors OR writers)</span>
110
+ </pre>
111
+
112
+ <p>Find records without any bitmask set:</p>
113
+
114
+ <pre class="ruby"><span class="ruby-constant">User</span>.<span class="ruby-identifier">without_roles</span>
115
+ <span class="ruby-comment"># =&gt; (all users without a role)</span>
116
+ <span class="ruby-constant">User</span>.<span class="ruby-identifier">no_roles</span>
117
+ <span class="ruby-comment"># =&gt; (all users without a role)</span>
118
+ </pre>
119
+
120
+ <p>Find records without a specific attribute.</p>
121
+
122
+ <pre class="ruby"><span class="ruby-constant">User</span>.<span class="ruby-identifier">without_roles</span>(:<span class="ruby-identifier">editor</span>)
123
+ <span class="ruby-comment"># =&gt; (all users who are not editors)</span>
124
+ </pre>
125
+
126
+ <p>Note that “without_” only supports a single attribute argument, and the
127
+ “no_” method does not support arguments.</p>
128
+
129
+ <h3 id="label-Adding+Methods">Adding Methods</h3>
130
+
131
+ <p>You can add your own methods to the bitmasked attributes (similar to named
132
+ scopes):</p>
133
+
134
+ <pre class="ruby"><span class="ruby-identifier">bitmask</span> :<span class="ruby-identifier">other_attribute</span>, :<span class="ruby-identifier">as</span> =<span class="ruby-operator">&gt;</span> [:<span class="ruby-identifier">value1</span>, :<span class="ruby-identifier">value2</span>] <span class="ruby-keyword">do</span>
135
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">worked?</span>
136
+ <span class="ruby-keyword">true</span>
137
+ <span class="ruby-keyword">end</span>
138
+ <span class="ruby-keyword">end</span>
139
+
140
+ <span class="ruby-identifier">user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">first</span>
141
+ <span class="ruby-identifier">user</span>.<span class="ruby-identifier">other_attribute</span>.<span class="ruby-identifier">worked?</span>
142
+ <span class="ruby-comment"># =&gt; true</span>
143
+ </pre>
144
+
145
+ <h3 id="label-Warning%3A+Modifying+possible+values">Warning: Modifying possible values</h3>
146
+
147
+ <p>IMPORTANT: Once you have data using a bitmask, don’t change the order of
148
+ the values, remove any values, or insert any new values in the `:as` array
149
+ anywhere except at the end. You won’t like the results.</p>
150
+
151
+ <h3 id="label-Contributing">Contributing</h3>
152
+ <ol><li>
153
+ <p>Fork it.</p>
154
+ </li><li>
155
+ <p>Create a branch (`git checkout -b new-feature`)</p>
156
+ </li><li>
157
+ <p>Make your changes</p>
158
+ </li><li>
159
+ <p>Run the tests (`bundle install` then `bundle exec rake`)</p>
160
+ </li><li>
161
+ <p>Commit your changes (`git commit -am “Created new feature”`)</p>
162
+ </li><li>
163
+ <p>Push to the branch (`git push origin new-feature`)</p>
164
+ </li><li>
165
+ <p>Create a <a href="http://help.github.com/send-pull-requests/">pull
166
+ request</a> from your branch.</p>
167
+ </li><li>
168
+ <p>Promote it. Get others to drop in and +1 it.</p>
169
+ </li></ol>
170
+
171
+ <h3 id="label-Credits">Credits</h3>
172
+
173
+ <p>Thanks to <a href="https://github.com/bruce">Bruce Williams</a> and the
174
+ following contributors of the bitmask-attribute plugin:</p>
175
+ <ul><li>
176
+ <p><a href="http://github.com/ambethia">Jason L Perry</a></p>
177
+ </li><li>
178
+ <p><a href="http://github.com/nfo">Nicolas Fouché</a></p>
179
+ </li><li>
180
+ <p><a href="http://github.com/IvanBuiko">Ivan Buiko</a></p>
181
+ </li></ul>
182
+
183
+ <h3 id="label-Copyright">Copyright</h3>
184
+
185
+ <p>Copyright © 2007-2009 Bruce Williams &amp; 2011 Joel Moss. See LICENSE for
186
+ details.</p>
187
+
188
+ </div>
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+ <!-- Methods -->
221
+ </div>
222
+ </div>
223
+ </body>
224
+ </html>
@@ -0,0 +1,83 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <title>definition.rb</title>
7
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
8
+ <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
9
+ <link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
10
+ <link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
11
+ <script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
12
+ <script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
13
+ <script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
14
+ <script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
15
+
16
+ </head>
17
+
18
+ <body>
19
+ <div class="banner">
20
+
21
+ <h1>
22
+ definition.rb
23
+ </h1>
24
+ <ul class="files">
25
+ <li>lib/bitmask_attributes/definition.rb</li>
26
+ <li>Last modified: 2011-11-23 09:14:04 +0000</li>
27
+ </ul>
28
+ </div>
29
+
30
+ <div id="bodyContent">
31
+ <div id="content">
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ <!-- Namespace -->
44
+ <div class="sectiontitle">Namespace</div>
45
+ <ul>
46
+
47
+ <li>
48
+ <span class="type">MODULE</span>
49
+ <a href="../../../classes/BitmaskAttributes.html">BitmaskAttributes</a>
50
+ </li>
51
+
52
+ <li>
53
+ <span class="type">CLASS</span>
54
+ <a href="../../../classes/BitmaskAttributes/Definition.html">BitmaskAttributes::Definition</a>
55
+ </li>
56
+
57
+ </ul>
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+ <!-- Methods -->
80
+ </div>
81
+ </div>
82
+ </body>
83
+ </html>
@@ -0,0 +1,83 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <title>value_proxy.rb</title>
7
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
8
+ <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
9
+ <link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
10
+ <link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
11
+ <script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
12
+ <script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
13
+ <script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
14
+ <script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
15
+
16
+ </head>
17
+
18
+ <body>
19
+ <div class="banner">
20
+
21
+ <h1>
22
+ value_proxy.rb
23
+ </h1>
24
+ <ul class="files">
25
+ <li>lib/bitmask_attributes/value_proxy.rb</li>
26
+ <li>Last modified: 2011-11-05 10:41:43 +0000</li>
27
+ </ul>
28
+ </div>
29
+
30
+ <div id="bodyContent">
31
+ <div id="content">
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ <!-- Namespace -->
44
+ <div class="sectiontitle">Namespace</div>
45
+ <ul>
46
+
47
+ <li>
48
+ <span class="type">MODULE</span>
49
+ <a href="../../../classes/BitmaskAttributes.html">BitmaskAttributes</a>
50
+ </li>
51
+
52
+ <li>
53
+ <span class="type">CLASS</span>
54
+ <a href="../../../classes/BitmaskAttributes/ValueProxy.html">BitmaskAttributes::ValueProxy</a>
55
+ </li>
56
+
57
+ </ul>
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+ <!-- Methods -->
80
+ </div>
81
+ </div>
82
+ </body>
83
+ </html>
@@ -0,0 +1,78 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <title>version.rb</title>
7
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
8
+ <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
9
+ <link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
10
+ <link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
11
+ <script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
12
+ <script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
13
+ <script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
14
+ <script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
15
+
16
+ </head>
17
+
18
+ <body>
19
+ <div class="banner">
20
+
21
+ <h1>
22
+ version.rb
23
+ </h1>
24
+ <ul class="files">
25
+ <li>lib/bitmask_attributes/version.rb</li>
26
+ <li>Last modified: 2011-11-23 09:26:01 +0000</li>
27
+ </ul>
28
+ </div>
29
+
30
+ <div id="bodyContent">
31
+ <div id="content">
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ <!-- Namespace -->
44
+ <div class="sectiontitle">Namespace</div>
45
+ <ul>
46
+
47
+ <li>
48
+ <span class="type">MODULE</span>
49
+ <a href="../../../classes/BitmaskAttributes.html">BitmaskAttributes</a>
50
+ </li>
51
+
52
+ </ul>
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+ <!-- Methods -->
75
+ </div>
76
+ </div>
77
+ </body>
78
+ </html>