bitmask_attributes 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
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,205 @@
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>BitmaskAttributes::ClassMethods</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
+ <span class="type">Module</span>
23
+ BitmaskAttributes::ClassMethods
24
+
25
+ </h1>
26
+ <ul class="files">
27
+
28
+ <li><a href="../../files/lib/bitmask_attributes_rb.html">lib/bitmask_attributes.rb</a></li>
29
+
30
+ </ul>
31
+ </div>
32
+ <div id="bodyContent">
33
+ <div id="content">
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+ <!-- Method ref -->
49
+ <div class="sectiontitle">Methods</div>
50
+ <dl class="methods">
51
+
52
+ <dt>B</dt>
53
+ <dd>
54
+ <ul>
55
+
56
+
57
+ <li>
58
+ <a href="#method-i-bitmask">bitmask</a>,
59
+ </li>
60
+
61
+
62
+ <li>
63
+ <a href="#method-i-bitmask_definitions">bitmask_definitions</a>,
64
+ </li>
65
+
66
+
67
+ <li>
68
+ <a href="#method-i-bitmasks">bitmasks</a>
69
+ </li>
70
+
71
+ </ul>
72
+ </dd>
73
+
74
+ </dl>
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+ <!-- Methods -->
94
+
95
+ <div class="sectiontitle">Instance Public methods</div>
96
+
97
+ <div class="method">
98
+ <div class="title method-title" id="method-i-bitmask">
99
+
100
+ <a name="method-i-bitmask"></a><b>bitmask</b>(attribute, options={}, &amp;extension)
101
+
102
+ </div>
103
+
104
+
105
+ <div class="description">
106
+
107
+ </div>
108
+
109
+
110
+
111
+
112
+
113
+
114
+ <div class="sourcecode">
115
+
116
+ <p class="source-link">
117
+ Source:
118
+ <a href="javascript:toggleSource('method-i-bitmask_source')" id="l_method-i-bitmask_source">show</a>
119
+
120
+ </p>
121
+ <div id="method-i-bitmask_source" class="dyn-source">
122
+ <pre><span class="ruby-comment"># File lib/bitmask_attributes.rb, line 8</span>
123
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">bitmask</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-identifier">options</span>={}, &amp;<span class="ruby-identifier">extension</span>)
124
+ <span class="ruby-keyword">unless</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:as</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:as</span>].<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Array</span>)
125
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;Must provide an Array :as option&quot;</span>
126
+ <span class="ruby-keyword">end</span>
127
+ <span class="ruby-identifier">bitmask_definitions</span>[<span class="ruby-identifier">attribute</span>] = <span class="ruby-constant">Definition</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-identifier">options</span>[<span class="ruby-value">:as</span>].<span class="ruby-identifier">to_a</span>, &amp;<span class="ruby-identifier">extension</span>)
128
+ <span class="ruby-identifier">bitmask_definitions</span>[<span class="ruby-identifier">attribute</span>].<span class="ruby-identifier">install_on</span>(<span class="ruby-keyword">self</span>)
129
+ <span class="ruby-keyword">end</span></pre>
130
+ </div>
131
+ </div>
132
+
133
+ </div>
134
+
135
+ <div class="method">
136
+ <div class="title method-title" id="method-i-bitmask_definitions">
137
+
138
+ <a name="method-i-bitmask_definitions"></a><b>bitmask_definitions</b>()
139
+
140
+ </div>
141
+
142
+
143
+ <div class="description">
144
+
145
+ </div>
146
+
147
+
148
+
149
+
150
+
151
+
152
+ <div class="sourcecode">
153
+
154
+ <p class="source-link">
155
+ Source:
156
+ <a href="javascript:toggleSource('method-i-bitmask_definitions_source')" id="l_method-i-bitmask_definitions_source">show</a>
157
+
158
+ </p>
159
+ <div id="method-i-bitmask_definitions_source" class="dyn-source">
160
+ <pre><span class="ruby-comment"># File lib/bitmask_attributes.rb, line 16</span>
161
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">bitmask_definitions</span>
162
+ <span class="ruby-ivar">@bitmask_definitions</span> <span class="ruby-operator">||=</span> {}
163
+ <span class="ruby-keyword">end</span></pre>
164
+ </div>
165
+ </div>
166
+
167
+ </div>
168
+
169
+ <div class="method">
170
+ <div class="title method-title" id="method-i-bitmasks">
171
+
172
+ <a name="method-i-bitmasks"></a><b>bitmasks</b>()
173
+
174
+ </div>
175
+
176
+
177
+ <div class="description">
178
+
179
+ </div>
180
+
181
+
182
+
183
+
184
+
185
+
186
+ <div class="sourcecode">
187
+
188
+ <p class="source-link">
189
+ Source:
190
+ <a href="javascript:toggleSource('method-i-bitmasks_source')" id="l_method-i-bitmasks_source">show</a>
191
+
192
+ </p>
193
+ <div id="method-i-bitmasks_source" class="dyn-source">
194
+ <pre><span class="ruby-comment"># File lib/bitmask_attributes.rb, line 20</span>
195
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">bitmasks</span>
196
+ <span class="ruby-ivar">@bitmasks</span> <span class="ruby-operator">||=</span> {}
197
+ <span class="ruby-keyword">end</span></pre>
198
+ </div>
199
+ </div>
200
+
201
+ </div>
202
+ </div>
203
+ </div>
204
+ </body>
205
+ </html>
@@ -0,0 +1,690 @@
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>BitmaskAttributes::Definition</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
+ <span class="type">Class</span>
23
+ BitmaskAttributes::Definition
24
+
25
+ <span class="parent">&lt;
26
+
27
+ Object
28
+
29
+ </span>
30
+
31
+ </h1>
32
+ <ul class="files">
33
+
34
+ <li><a href="../../files/lib/bitmask_attributes/definition_rb.html">lib/bitmask_attributes/definition.rb</a></li>
35
+
36
+ </ul>
37
+ </div>
38
+ <div id="bodyContent">
39
+ <div id="content">
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+ <!-- Method ref -->
55
+ <div class="sectiontitle">Methods</div>
56
+ <dl class="methods">
57
+
58
+ <dt>C</dt>
59
+ <dd>
60
+ <ul>
61
+
62
+
63
+ <li>
64
+ <a href="#method-i-create_attribute_methods_on">create_attribute_methods_on</a>,
65
+ </li>
66
+
67
+
68
+ <li>
69
+ <a href="#method-i-create_convenience_class_method_on">create_convenience_class_method_on</a>,
70
+ </li>
71
+
72
+
73
+ <li>
74
+ <a href="#method-i-create_convenience_instance_methods_on">create_convenience_instance_methods_on</a>,
75
+ </li>
76
+
77
+
78
+ <li>
79
+ <a href="#method-i-create_scopes_on">create_scopes_on</a>
80
+ </li>
81
+
82
+ </ul>
83
+ </dd>
84
+
85
+ <dt>G</dt>
86
+ <dd>
87
+ <ul>
88
+
89
+
90
+ <li>
91
+ <a href="#method-i-generate_bitmasks_on">generate_bitmasks_on</a>
92
+ </li>
93
+
94
+ </ul>
95
+ </dd>
96
+
97
+ <dt>I</dt>
98
+ <dd>
99
+ <ul>
100
+
101
+
102
+ <li>
103
+ <a href="#method-i-install_on">install_on</a>
104
+ </li>
105
+
106
+ </ul>
107
+ </dd>
108
+
109
+ <dt>N</dt>
110
+ <dd>
111
+ <ul>
112
+
113
+
114
+ <li>
115
+ <a href="#method-c-new">new</a>
116
+ </li>
117
+
118
+ </ul>
119
+ </dd>
120
+
121
+ <dt>O</dt>
122
+ <dd>
123
+ <ul>
124
+
125
+
126
+ <li>
127
+ <a href="#method-i-override">override</a>,
128
+ </li>
129
+
130
+
131
+ <li>
132
+ <a href="#method-i-override_getter_on">override_getter_on</a>,
133
+ </li>
134
+
135
+
136
+ <li>
137
+ <a href="#method-i-override_setter_on">override_setter_on</a>
138
+ </li>
139
+
140
+ </ul>
141
+ </dd>
142
+
143
+ <dt>V</dt>
144
+ <dd>
145
+ <ul>
146
+
147
+
148
+ <li>
149
+ <a href="#method-i-validate_for">validate_for</a>
150
+ </li>
151
+
152
+ </ul>
153
+ </dd>
154
+
155
+ </dl>
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+ <!-- Section attributes -->
173
+ <div class="sectiontitle">Attributes</div>
174
+ <table border='0' cellpadding='5'>
175
+
176
+ <tr valign='top'>
177
+ <td class='attr-rw'>
178
+ [R]
179
+ </td>
180
+ <td class='attr-name'>attribute</td>
181
+ <td class='attr-desc'></td>
182
+ </tr>
183
+
184
+ <tr valign='top'>
185
+ <td class='attr-rw'>
186
+ [R]
187
+ </td>
188
+ <td class='attr-name'>extension</td>
189
+ <td class='attr-desc'></td>
190
+ </tr>
191
+
192
+ <tr valign='top'>
193
+ <td class='attr-rw'>
194
+ [R]
195
+ </td>
196
+ <td class='attr-name'>values</td>
197
+ <td class='attr-desc'></td>
198
+ </tr>
199
+
200
+ </table>
201
+
202
+
203
+
204
+ <!-- Methods -->
205
+
206
+ <div class="sectiontitle">Class Public methods</div>
207
+
208
+ <div class="method">
209
+ <div class="title method-title" id="method-c-new">
210
+
211
+ <a name="method-c-new"></a><b>new</b>(attribute, values=[], &amp;extension)
212
+
213
+ </div>
214
+
215
+
216
+ <div class="description">
217
+
218
+ </div>
219
+
220
+
221
+
222
+
223
+
224
+
225
+ <div class="sourcecode">
226
+
227
+ <p class="source-link">
228
+ Source:
229
+ <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
230
+
231
+ </p>
232
+ <div id="method-c-new_source" class="dyn-source">
233
+ <pre><span class="ruby-comment"># File lib/bitmask_attributes/definition.rb, line 5</span>
234
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-identifier">values</span>=[], &amp;<span class="ruby-identifier">extension</span>)
235
+ <span class="ruby-ivar">@attribute</span> = <span class="ruby-identifier">attribute</span>
236
+ <span class="ruby-ivar">@values</span> = <span class="ruby-identifier">values</span>
237
+ <span class="ruby-ivar">@extension</span> = <span class="ruby-identifier">extension</span>
238
+ <span class="ruby-keyword">end</span></pre>
239
+ </div>
240
+ </div>
241
+
242
+ </div>
243
+
244
+ <div class="sectiontitle">Instance Public methods</div>
245
+
246
+ <div class="method">
247
+ <div class="title method-title" id="method-i-install_on">
248
+
249
+ <a name="method-i-install_on"></a><b>install_on</b>(model)
250
+
251
+ </div>
252
+
253
+
254
+ <div class="description">
255
+
256
+ </div>
257
+
258
+
259
+
260
+
261
+
262
+
263
+ <div class="sourcecode">
264
+
265
+ <p class="source-link">
266
+ Source:
267
+ <a href="javascript:toggleSource('method-i-install_on_source')" id="l_method-i-install_on_source">show</a>
268
+
269
+ </p>
270
+ <div id="method-i-install_on_source" class="dyn-source">
271
+ <pre><span class="ruby-comment"># File lib/bitmask_attributes/definition.rb, line 11</span>
272
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">install_on</span>(<span class="ruby-identifier">model</span>)
273
+ <span class="ruby-identifier">validate_for</span> <span class="ruby-identifier">model</span>
274
+ <span class="ruby-identifier">generate_bitmasks_on</span> <span class="ruby-identifier">model</span>
275
+ <span class="ruby-identifier">override</span> <span class="ruby-identifier">model</span>
276
+ <span class="ruby-identifier">create_convenience_class_method_on</span> <span class="ruby-identifier">model</span>
277
+ <span class="ruby-identifier">create_convenience_instance_methods_on</span> <span class="ruby-identifier">model</span>
278
+ <span class="ruby-identifier">create_scopes_on</span> <span class="ruby-identifier">model</span>
279
+ <span class="ruby-identifier">create_attribute_methods_on</span> <span class="ruby-identifier">model</span>
280
+ <span class="ruby-keyword">end</span></pre>
281
+ </div>
282
+ </div>
283
+
284
+ </div>
285
+
286
+ <div class="sectiontitle">Instance Private methods</div>
287
+
288
+ <div class="method">
289
+ <div class="title method-title" id="method-i-create_attribute_methods_on">
290
+
291
+ <a name="method-i-create_attribute_methods_on"></a><b>create_attribute_methods_on</b>(model)
292
+
293
+ </div>
294
+
295
+
296
+ <div class="description">
297
+ <p>Returns the defined values as an Array.</p>
298
+ </div>
299
+
300
+
301
+
302
+
303
+
304
+
305
+ <div class="sourcecode">
306
+
307
+ <p class="source-link">
308
+ Source:
309
+ <a href="javascript:toggleSource('method-i-create_attribute_methods_on_source')" id="l_method-i-create_attribute_methods_on_source">show</a>
310
+
311
+ </p>
312
+ <div id="method-i-create_attribute_methods_on_source" class="dyn-source">
313
+ <pre><span class="ruby-comment"># File lib/bitmask_attributes/definition.rb, line 65</span>
314
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">create_attribute_methods_on</span>(<span class="ruby-identifier">model</span>)
315
+ <span class="ruby-identifier">model</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-node">%Q(
316
+ def self.values_for_#{attribute} # def self.values_for_numbers
317
+ #{values} # [:one, :two, :three]
318
+ end # end
319
+ )</span>
320
+ <span class="ruby-keyword">end</span></pre>
321
+ </div>
322
+ </div>
323
+
324
+ </div>
325
+
326
+ <div class="method">
327
+ <div class="title method-title" id="method-i-create_convenience_class_method_on">
328
+
329
+ <a name="method-i-create_convenience_class_method_on"></a><b>create_convenience_class_method_on</b>(model)
330
+
331
+ </div>
332
+
333
+
334
+ <div class="description">
335
+
336
+ </div>
337
+
338
+
339
+
340
+
341
+
342
+
343
+ <div class="sourcecode">
344
+
345
+ <p class="source-link">
346
+ Source:
347
+ <a href="javascript:toggleSource('method-i-create_convenience_class_method_on_source')" id="l_method-i-create_convenience_class_method_on_source">show</a>
348
+
349
+ </p>
350
+ <div id="method-i-create_convenience_class_method_on_source" class="dyn-source">
351
+ <pre><span class="ruby-comment"># File lib/bitmask_attributes/definition.rb, line 73</span>
352
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">create_convenience_class_method_on</span>(<span class="ruby-identifier">model</span>)
353
+ <span class="ruby-identifier">model</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-node">%Q(
354
+ def self.bitmask_for_#{attribute}(*values)
355
+ values.inject(0) do |bitmask, value|
356
+ unless (bit = bitmasks[:#{attribute}][value])
357
+ raise ArgumentError, &quot;Unsupported value for #{attribute}: \#{value.inspect}&quot;
358
+ end
359
+ bitmask | bit
360
+ end
361
+ end
362
+ )</span>
363
+ <span class="ruby-keyword">end</span></pre>
364
+ </div>
365
+ </div>
366
+
367
+ </div>
368
+
369
+ <div class="method">
370
+ <div class="title method-title" id="method-i-create_convenience_instance_methods_on">
371
+
372
+ <a name="method-i-create_convenience_instance_methods_on"></a><b>create_convenience_instance_methods_on</b>(model)
373
+
374
+ </div>
375
+
376
+
377
+ <div class="description">
378
+
379
+ </div>
380
+
381
+
382
+
383
+
384
+
385
+
386
+ <div class="sourcecode">
387
+
388
+ <p class="source-link">
389
+ Source:
390
+ <a href="javascript:toggleSource('method-i-create_convenience_instance_methods_on_source')" id="l_method-i-create_convenience_instance_methods_on_source">show</a>
391
+
392
+ </p>
393
+ <div id="method-i-create_convenience_instance_methods_on_source" class="dyn-source">
394
+ <pre><span class="ruby-comment"># File lib/bitmask_attributes/definition.rb, line 86</span>
395
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">create_convenience_instance_methods_on</span>(<span class="ruby-identifier">model</span>)
396
+ <span class="ruby-identifier">values</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
397
+ <span class="ruby-identifier">model</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-node">%Q(
398
+ def #{attribute}_for_#{value}?
399
+ self.#{attribute}?(:#{value})
400
+ end
401
+ )</span>
402
+ <span class="ruby-keyword">end</span>
403
+ <span class="ruby-identifier">model</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-node">%Q(
404
+ def #{attribute}?(*values)
405
+ if !values.blank?
406
+ values.all? do |value|
407
+ self.#{attribute}.include?(value)
408
+ end
409
+ else
410
+ self.#{attribute}.present?
411
+ end
412
+ end
413
+ )</span>
414
+ <span class="ruby-keyword">end</span></pre>
415
+ </div>
416
+ </div>
417
+
418
+ </div>
419
+
420
+ <div class="method">
421
+ <div class="title method-title" id="method-i-create_scopes_on">
422
+
423
+ <a name="method-i-create_scopes_on"></a><b>create_scopes_on</b>(model)
424
+
425
+ </div>
426
+
427
+
428
+ <div class="description">
429
+
430
+ </div>
431
+
432
+
433
+
434
+
435
+
436
+
437
+ <div class="sourcecode">
438
+
439
+ <p class="source-link">
440
+ Source:
441
+ <a href="javascript:toggleSource('method-i-create_scopes_on_source')" id="l_method-i-create_scopes_on_source">show</a>
442
+
443
+ </p>
444
+ <div id="method-i-create_scopes_on_source" class="dyn-source">
445
+ <pre><span class="ruby-comment"># File lib/bitmask_attributes/definition.rb, line 107</span>
446
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">create_scopes_on</span>(<span class="ruby-identifier">model</span>)
447
+ <span class="ruby-identifier">model</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-node">%Q(
448
+ scope :with_#{attribute},
449
+ proc { |*values|
450
+ if values.blank?
451
+ where('#{attribute} &gt; 0 OR #{attribute} IS NOT NULL')
452
+ else
453
+ sets = values.map do |value|
454
+ mask = #{model}.bitmask_for_#{attribute}(value)
455
+ &quot;#{attribute} &amp; \#{mask} &lt;&gt; 0&quot;
456
+ end
457
+ where(sets.join(' AND '))
458
+ end
459
+ }
460
+ scope :without_#{attribute},
461
+ proc { |value|
462
+ if value
463
+ mask = #{model}.bitmask_for_#{attribute}(value)
464
+ where(&quot;#{attribute} IS NULL OR #{attribute} &amp; ? = 0&quot;, mask)
465
+ else
466
+ where(&quot;#{attribute} IS NULL OR #{attribute} = 0&quot;)
467
+ end
468
+ }
469
+
470
+ scope :no_#{attribute}, where(&quot;#{attribute} = 0 OR #{attribute} IS NULL&quot;)
471
+
472
+ scope :with_any_#{attribute},
473
+ proc { |*values|
474
+ if values.blank?
475
+ where('#{attribute} &gt; 0 OR #{attribute} IS NOT NULL')
476
+ else
477
+ sets = values.map do |value|
478
+ mask = #{model}.bitmask_for_#{attribute}(value)
479
+ &quot;#{attribute} &amp; \#{mask} &lt;&gt; 0&quot;
480
+ end
481
+ where(sets.join(' OR '))
482
+ end
483
+ }
484
+ )</span>
485
+ <span class="ruby-identifier">values</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
486
+ <span class="ruby-identifier">model</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-node">%Q(
487
+ scope :#{attribute}_for_#{value},
488
+ where('#{attribute} &amp; ? &lt;&gt; 0', #{model}.bitmask_for_#{attribute}(:#{value}))
489
+ )</span>
490
+ <span class="ruby-keyword">end</span>
491
+ <span class="ruby-keyword">end</span></pre>
492
+ </div>
493
+ </div>
494
+
495
+ </div>
496
+
497
+ <div class="method">
498
+ <div class="title method-title" id="method-i-generate_bitmasks_on">
499
+
500
+ <a name="method-i-generate_bitmasks_on"></a><b>generate_bitmasks_on</b>(model)
501
+
502
+ </div>
503
+
504
+
505
+ <div class="description">
506
+
507
+ </div>
508
+
509
+
510
+
511
+
512
+
513
+
514
+ <div class="sourcecode">
515
+
516
+ <p class="source-link">
517
+ Source:
518
+ <a href="javascript:toggleSource('method-i-generate_bitmasks_on_source')" id="l_method-i-generate_bitmasks_on_source">show</a>
519
+
520
+ </p>
521
+ <div id="method-i-generate_bitmasks_on_source" class="dyn-source">
522
+ <pre><span class="ruby-comment"># File lib/bitmask_attributes/definition.rb, line 34</span>
523
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">generate_bitmasks_on</span>(<span class="ruby-identifier">model</span>)
524
+ <span class="ruby-identifier">model</span>.<span class="ruby-identifier">bitmasks</span>[<span class="ruby-identifier">attribute</span>] = <span class="ruby-constant">HashWithIndifferentAccess</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">tap</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mapping</span><span class="ruby-operator">|</span>
525
+ <span class="ruby-identifier">values</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">value</span>, <span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
526
+ <span class="ruby-identifier">mapping</span>[<span class="ruby-identifier">value</span>] = <span class="ruby-number">0b1</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">index</span>
527
+ <span class="ruby-keyword">end</span>
528
+ <span class="ruby-keyword">end</span>
529
+ <span class="ruby-keyword">end</span></pre>
530
+ </div>
531
+ </div>
532
+
533
+ </div>
534
+
535
+ <div class="method">
536
+ <div class="title method-title" id="method-i-override">
537
+
538
+ <a name="method-i-override"></a><b>override</b>(model)
539
+
540
+ </div>
541
+
542
+
543
+ <div class="description">
544
+
545
+ </div>
546
+
547
+
548
+
549
+
550
+
551
+
552
+ <div class="sourcecode">
553
+
554
+ <p class="source-link">
555
+ Source:
556
+ <a href="javascript:toggleSource('method-i-override_source')" id="l_method-i-override_source">show</a>
557
+
558
+ </p>
559
+ <div id="method-i-override_source" class="dyn-source">
560
+ <pre><span class="ruby-comment"># File lib/bitmask_attributes/definition.rb, line 42</span>
561
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">override</span>(<span class="ruby-identifier">model</span>)
562
+ <span class="ruby-identifier">override_getter_on</span>(<span class="ruby-identifier">model</span>)
563
+ <span class="ruby-identifier">override_setter_on</span>(<span class="ruby-identifier">model</span>)
564
+ <span class="ruby-keyword">end</span></pre>
565
+ </div>
566
+ </div>
567
+
568
+ </div>
569
+
570
+ <div class="method">
571
+ <div class="title method-title" id="method-i-override_getter_on">
572
+
573
+ <a name="method-i-override_getter_on"></a><b>override_getter_on</b>(model)
574
+
575
+ </div>
576
+
577
+
578
+ <div class="description">
579
+
580
+ </div>
581
+
582
+
583
+
584
+
585
+
586
+
587
+ <div class="sourcecode">
588
+
589
+ <p class="source-link">
590
+ Source:
591
+ <a href="javascript:toggleSource('method-i-override_getter_on_source')" id="l_method-i-override_getter_on_source">show</a>
592
+
593
+ </p>
594
+ <div id="method-i-override_getter_on_source" class="dyn-source">
595
+ <pre><span class="ruby-comment"># File lib/bitmask_attributes/definition.rb, line 47</span>
596
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">override_getter_on</span>(<span class="ruby-identifier">model</span>)
597
+ <span class="ruby-identifier">model</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-node">%Q(
598
+ def #{attribute}
599
+ @#{attribute} ||= BitmaskAttributes::ValueProxy.new(self, :#{attribute}, &amp;self.class.bitmask_definitions[:#{attribute}].extension)
600
+ end
601
+ )</span>
602
+ <span class="ruby-keyword">end</span></pre>
603
+ </div>
604
+ </div>
605
+
606
+ </div>
607
+
608
+ <div class="method">
609
+ <div class="title method-title" id="method-i-override_setter_on">
610
+
611
+ <a name="method-i-override_setter_on"></a><b>override_setter_on</b>(model)
612
+
613
+ </div>
614
+
615
+
616
+ <div class="description">
617
+
618
+ </div>
619
+
620
+
621
+
622
+
623
+
624
+
625
+ <div class="sourcecode">
626
+
627
+ <p class="source-link">
628
+ Source:
629
+ <a href="javascript:toggleSource('method-i-override_setter_on_source')" id="l_method-i-override_setter_on_source">show</a>
630
+
631
+ </p>
632
+ <div id="method-i-override_setter_on_source" class="dyn-source">
633
+ <pre><span class="ruby-comment"># File lib/bitmask_attributes/definition.rb, line 55</span>
634
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">override_setter_on</span>(<span class="ruby-identifier">model</span>)
635
+ <span class="ruby-identifier">model</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-node">%Q(
636
+ def #{attribute}=(raw_value)
637
+ values = raw_value.kind_of?(Array) ? raw_value : [raw_value]
638
+ self.#{attribute}.replace(values.reject(&amp;:blank?))
639
+ end
640
+ )</span>
641
+ <span class="ruby-keyword">end</span></pre>
642
+ </div>
643
+ </div>
644
+
645
+ </div>
646
+
647
+ <div class="method">
648
+ <div class="title method-title" id="method-i-validate_for">
649
+
650
+ <a name="method-i-validate_for"></a><b>validate_for</b>(model)
651
+
652
+ </div>
653
+
654
+
655
+ <div class="description">
656
+
657
+ </div>
658
+
659
+
660
+
661
+
662
+
663
+
664
+ <div class="sourcecode">
665
+
666
+ <p class="source-link">
667
+ Source:
668
+ <a href="javascript:toggleSource('method-i-validate_for_source')" id="l_method-i-validate_for_source">show</a>
669
+
670
+ </p>
671
+ <div id="method-i-validate_for_source" class="dyn-source">
672
+ <pre><span class="ruby-comment"># File lib/bitmask_attributes/definition.rb, line 23</span>
673
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">validate_for</span>(<span class="ruby-identifier">model</span>)
674
+ <span class="ruby-comment"># The model cannot be validated if it is preloaded and the attribute/column is not in the</span>
675
+ <span class="ruby-comment"># database (the migration has not been run) or table doesn't exist. This usually</span>
676
+ <span class="ruby-comment"># occurs in the 'test' and 'production' environment or during migration.</span>
677
+ <span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-constant">Rails</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">configuration</span>.<span class="ruby-identifier">cache_classes</span> <span class="ruby-operator">||</span> <span class="ruby-operator">!</span><span class="ruby-identifier">model</span>.<span class="ruby-identifier">table_exists?</span>
678
+
679
+ <span class="ruby-keyword">unless</span> <span class="ruby-identifier">model</span>.<span class="ruby-identifier">columns</span>.<span class="ruby-identifier">detect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">col</span><span class="ruby-operator">|</span> <span class="ruby-identifier">col</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">to_s</span> }
680
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;`#{attribute}' is not an attribute of `#{model}'&quot;</span>
681
+ <span class="ruby-keyword">end</span>
682
+ <span class="ruby-keyword">end</span></pre>
683
+ </div>
684
+ </div>
685
+
686
+ </div>
687
+ </div>
688
+ </div>
689
+ </body>
690
+ </html>