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,228 @@
1
+ Searcher = function(data) {
2
+ this.data = data;
3
+ this.handlers = [];
4
+ }
5
+
6
+ Searcher.prototype = new function() {
7
+ // search is performed in chunks of 1000 for non-blocking user input
8
+ var CHUNK_SIZE = 1000;
9
+ // do not try to find more than 100 results
10
+ var MAX_RESULTS = 100;
11
+ var huid = 1;
12
+ var suid = 1;
13
+ var runs = 0;
14
+
15
+ this.find = function(query) {
16
+ var queries = splitQuery(query);
17
+ var regexps = buildRegexps(queries);
18
+ var highlighters = buildHilighters(queries);
19
+ var state = { from: 0, pass: 0, limit: MAX_RESULTS, n: suid++};
20
+ var _this = this;
21
+
22
+ this.currentSuid = state.n;
23
+
24
+ if (!query) return;
25
+
26
+ var run = function() {
27
+ // stop current search thread if new search started
28
+ if (state.n != _this.currentSuid) return;
29
+
30
+ var results =
31
+ performSearch(_this.data, regexps, queries, highlighters, state);
32
+ var hasMore = (state.limit > 0 && state.pass < 4);
33
+
34
+ triggerResults.call(_this, results, !hasMore);
35
+ if (hasMore) {
36
+ setTimeout(run, 2);
37
+ }
38
+ runs++;
39
+ };
40
+ runs = 0;
41
+
42
+ // start search thread
43
+ run();
44
+ }
45
+
46
+ /* ----- Events ------ */
47
+ this.ready = function(fn) {
48
+ fn.huid = huid;
49
+ this.handlers.push(fn);
50
+ }
51
+
52
+ /* ----- Utilities ------ */
53
+ function splitQuery(query) {
54
+ return jQuery.grep(query.split(/(\s+|::?|\(\)?)/), function(string) {
55
+ return string.match(/\S/)
56
+ });
57
+ }
58
+
59
+ function buildRegexps(queries) {
60
+ return jQuery.map(queries, function(query) {
61
+ return new RegExp(query.replace(/(.)/g, '([$1])([^$1]*?)'), 'i')
62
+ });
63
+ }
64
+
65
+ function buildHilighters(queries) {
66
+ return jQuery.map(queries, function(query) {
67
+ return jQuery.map(query.split(''), function(l, i) {
68
+ return '\u0001$' + (i*2+1) + '\u0002$' + (i*2+2);
69
+ }).join('');
70
+ });
71
+ }
72
+
73
+ // function longMatchRegexp(index, longIndex, regexps) {
74
+ // for (var i = regexps.length - 1; i >= 0; i--){
75
+ // if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
76
+ // };
77
+ // return true;
78
+ // }
79
+
80
+
81
+ /* ----- Mathchers ------ */
82
+
83
+ /*
84
+ * This record matches if the index starts with queries[0] and the record
85
+ * matches all of the regexps
86
+ */
87
+ function matchPassBeginning(index, longIndex, queries, regexps) {
88
+ if (index.indexOf(queries[0]) != 0) return false;
89
+ for (var i=1, l = regexps.length; i < l; i++) {
90
+ if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
91
+ return false;
92
+ };
93
+ return true;
94
+ }
95
+
96
+ /*
97
+ * This record matches if the longIndex starts with queries[0] and the
98
+ * longIndex matches all of the regexps
99
+ */
100
+ function matchPassLongIndex(index, longIndex, queries, regexps) {
101
+ if (longIndex.indexOf(queries[0]) != 0) return false;
102
+ for (var i=1, l = regexps.length; i < l; i++) {
103
+ if (!longIndex.match(regexps[i]))
104
+ return false;
105
+ };
106
+ return true;
107
+ }
108
+
109
+ /*
110
+ * This record matches if the index contains queries[0] and the record
111
+ * matches all of the regexps
112
+ */
113
+ function matchPassContains(index, longIndex, queries, regexps) {
114
+ if (index.indexOf(queries[0]) == -1) return false;
115
+ for (var i=1, l = regexps.length; i < l; i++) {
116
+ if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
117
+ return false;
118
+ };
119
+ return true;
120
+ }
121
+
122
+ /*
123
+ * This record matches if regexps[0] matches the index and the record
124
+ * matches all of the regexps
125
+ */
126
+ function matchPassRegexp(index, longIndex, queries, regexps) {
127
+ if (!index.match(regexps[0])) return false;
128
+ for (var i=1, l = regexps.length; i < l; i++) {
129
+ if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
130
+ return false;
131
+ };
132
+ return true;
133
+ }
134
+
135
+
136
+ /* ----- Highlighters ------ */
137
+ function highlightRegexp(info, queries, regexps, highlighters) {
138
+ var result = createResult(info);
139
+ for (var i=0, l = regexps.length; i < l; i++) {
140
+ result.title = result.title.replace(regexps[i], highlighters[i]);
141
+ result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
142
+ };
143
+ return result;
144
+ }
145
+
146
+ function hltSubstring(string, pos, length) {
147
+ return string.substring(0, pos) + '\u0001' + string.substring(pos, pos + length) + '\u0002' + string.substring(pos + length);
148
+ }
149
+
150
+ function highlightQuery(info, queries, regexps, highlighters) {
151
+ var result = createResult(info);
152
+ var pos = 0;
153
+ var lcTitle = result.title.toLowerCase();
154
+
155
+ pos = lcTitle.indexOf(queries[0]);
156
+ if (pos != -1) {
157
+ result.title = hltSubstring(result.title, pos, queries[0].length);
158
+ }
159
+
160
+ result.namespace = result.namespace.replace(regexps[0], highlighters[0]);
161
+ for (var i=1, l = regexps.length; i < l; i++) {
162
+ result.title = result.title.replace(regexps[i], highlighters[i]);
163
+ result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
164
+ };
165
+ return result;
166
+ }
167
+
168
+ function createResult(info) {
169
+ var result = {};
170
+ result.title = info[0];
171
+ result.namespace = info[1];
172
+ result.path = info[2];
173
+ result.params = info[3];
174
+ result.snippet = info[4];
175
+ return result;
176
+ }
177
+
178
+ /* ----- Searching ------ */
179
+ function performSearch(data, regexps, queries, highlighters, state) {
180
+ var searchIndex = data.searchIndex;
181
+ var longSearchIndex = data.longSearchIndex;
182
+ var info = data.info;
183
+ var result = [];
184
+ var i = state.from;
185
+ var l = searchIndex.length;
186
+ var togo = CHUNK_SIZE;
187
+ var matchFunc, hltFunc;
188
+
189
+ while (state.pass < 4 && state.limit > 0 && togo > 0) {
190
+ if (state.pass == 0) {
191
+ matchFunc = matchPassBeginning;
192
+ hltFunc = highlightQuery;
193
+ } else if (state.pass == 1) {
194
+ matchFunc = matchPassLongIndex;
195
+ hltFunc = highlightQuery;
196
+ } else if (state.pass == 2) {
197
+ matchFunc = matchPassContains;
198
+ hltFunc = highlightQuery;
199
+ } else if (state.pass == 3) {
200
+ matchFunc = matchPassRegexp;
201
+ hltFunc = highlightRegexp;
202
+ }
203
+
204
+ for (; togo > 0 && i < l && state.limit > 0; i++, togo--) {
205
+ if (info[i].n == state.n) continue;
206
+ if (matchFunc(searchIndex[i], longSearchIndex[i], queries, regexps)) {
207
+ info[i].n = state.n;
208
+ result.push(hltFunc(info[i], queries, regexps, highlighters));
209
+ state.limit--;
210
+ }
211
+ };
212
+ if (searchIndex.length <= i) {
213
+ state.pass++;
214
+ i = state.from = 0;
215
+ } else {
216
+ state.from = i;
217
+ }
218
+ }
219
+ return result;
220
+ }
221
+
222
+ function triggerResults(results, isLast) {
223
+ jQuery.each(this.handlers, function(i, fn) {
224
+ fn.call(this, results, isLast)
225
+ })
226
+ }
227
+ }
228
+
@@ -0,0 +1,73 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3
+ "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4
+
5
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
6
+ <head>
7
+ <title>search index</title>
8
+ <link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" charset="utf-8" />
9
+ <link rel="stylesheet" href="../css/panel.css" type="text/css" media="screen" charset="utf-8" />
10
+ <script src="../js/search_index.js" type="text/javascript" charset="utf-8"></script>
11
+ <script src="../js/searcher.js" type="text/javascript" charset="utf-8"></script>
12
+ <script src="tree.js" type="text/javascript" charset="utf-8"></script>
13
+ <script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
14
+ <script src="../js/searchdoc.js" type="text/javascript" charset="utf-8"></script>
15
+ <script type="text/javascript" charset="utf-8">
16
+ function placeholder() {
17
+ if ($('<input type="text">')[0].placeholder !== undefined) return;
18
+
19
+ $('#search-label').click(function() {
20
+ $('#search').focus();
21
+ $('#search-label').hide();
22
+ });
23
+
24
+ $('#search').focus(function() {
25
+ $('#search-label').hide();
26
+ });
27
+ $('#search').blur(function() {
28
+ this.value == '' && $('#search-label').show()
29
+ });
30
+
31
+ $('#search')[0].value == '' && $('#search-label').show();
32
+ }
33
+ $(function() {
34
+ placeholder();
35
+ $('#links').hide();
36
+ var panel = new Searchdoc.Panel($('#panel'), search_data, tree, top.frames[1]);
37
+ $('#search').focus();
38
+
39
+ var s = window.parent.location.search.match(/\?q=([^&]+)/);
40
+ if (s) {
41
+ s = decodeURIComponent(s[1]).replace(/\+/g, ' ');
42
+ if (s.length > 0)
43
+ {
44
+ $('#search').val(s);
45
+ panel.search(s, true);
46
+ }
47
+ }
48
+ })
49
+ </script>
50
+ </head>
51
+ <body>
52
+ <div class="panel panel_tree" id="panel">
53
+ <div class="header">
54
+ <div>
55
+ <label for="search" id="search-label" style="display: none">Search</label>
56
+ <table>
57
+ <tr><td>
58
+ <input type="Search" placeholder="Search" autosave="searchdoc" results="10" id="search" autocomplete="off"/>
59
+ </td></tr>
60
+ </table></div>
61
+ </div>
62
+ <div class="tree">
63
+ <ul>
64
+ </ul>
65
+ </div>
66
+ <div class="result">
67
+ <ul>
68
+ </ul>
69
+ </div>
70
+ </div>
71
+ <a href="links.html" id="links">index</a>
72
+ </body>
73
+ </html>
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <head>File index</head>
3
+ <body>
4
+
5
+ <a href="../files/CHANGELOG_rdoc.html">CHANGELOG.rdoc</a>
6
+
7
+ <a href="../files/README_rdoc.html">README.rdoc</a>
8
+
9
+ <a href="../files/lib/bitmask_attributes_rb.html">lib/bitmask_attributes.rb</a>
10
+
11
+ <a href="../files/lib/bitmask_attributes/definition_rb.html">lib/bitmask_attributes/definition.rb</a>
12
+
13
+ <a href="../files/lib/bitmask_attributes/value_proxy_rb.html">lib/bitmask_attributes/value_proxy.rb</a>
14
+
15
+ <a href="../files/lib/bitmask_attributes/version_rb.html">lib/bitmask_attributes/version.rb</a>
16
+
17
+ </body>
18
+ </html>
@@ -0,0 +1 @@
1
+ var tree = [["","","files",[["CHANGELOG.rdoc","files/CHANGELOG_rdoc.html","",[]],["README.rdoc","files/README_rdoc.html","",[]],["","","lib",[["","","bitmask_attributes",[["definition.rb","files/lib/bitmask_attributes/definition_rb.html","",[]],["value_proxy.rb","files/lib/bitmask_attributes/value_proxy_rb.html","",[]],["version.rb","files/lib/bitmask_attributes/version_rb.html","",[]]]],["bitmask_attributes.rb","files/lib/bitmask_attributes_rb.html","",[]]]]]],["BitmaskAttributes","classes/BitmaskAttributes.html","",[["ClassMethods","classes/BitmaskAttributes/ClassMethods.html","",[]],["Definition","classes/BitmaskAttributes/Definition.html"," < Object",[]],["ValueProxy","classes/BitmaskAttributes/ValueProxy.html"," < Array",[]]]]]
@@ -22,10 +22,10 @@ module BitmaskAttributes
22
22
 
23
23
  def validate_for(model)
24
24
  # The model cannot be validated if it is preloaded and the attribute/column is not in the
25
- # database (the migration has not been run). This usually
26
- # occurs in the 'test' and 'production' environments.
27
- return if defined?(Rails) && Rails.configuration.cache_classes
28
-
25
+ # database (the migration has not been run) or table doesn't exist. This usually
26
+ # occurs in the 'test' and 'production' environment or during migration.
27
+ return if defined?(Rails) && Rails.configuration.cache_classes || !model.table_exists?
28
+
29
29
  unless model.columns.detect { |col| col.name == attribute.to_s }
30
30
  raise ArgumentError, "`#{attribute}' is not an attribute of `#{model}'"
31
31
  end
@@ -1,3 +1,3 @@
1
1
  module BitmaskAttributes
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitmask_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-05 00:00:00.000000000 Z
12
+ date: 2011-11-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70135687914640 !ruby/object:Gem::Requirement
16
+ requirement: &70229913138200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,8 +21,8 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70135687914640
25
- description: Simple bitmask attribute support for ActiveRecord
24
+ version_requirements: *70229913138200
25
+ description:
26
26
  email: joel@developwithstyle.com
27
27
  executables: []
28
28
  extensions: []
@@ -31,12 +31,45 @@ files:
31
31
  - .document
32
32
  - .gitignore
33
33
  - .rvmrc
34
+ - CHANGELOG.rdoc
34
35
  - Gemfile
35
36
  - Gemfile.lock
36
37
  - LICENSE
37
- - README.md
38
+ - README.rdoc
38
39
  - Rakefile
39
40
  - bitmask_attributes.gemspec
41
+ - doc/apple-touch-icon.png
42
+ - doc/classes/BitmaskAttributes.html
43
+ - doc/classes/BitmaskAttributes/ClassMethods.html
44
+ - doc/classes/BitmaskAttributes/Definition.html
45
+ - doc/classes/BitmaskAttributes/ValueProxy.html
46
+ - doc/created.rid
47
+ - doc/css/github.css
48
+ - doc/css/main.css
49
+ - doc/css/panel.css
50
+ - doc/css/reset.css
51
+ - doc/favicon.ico
52
+ - doc/files/CHANGELOG_rdoc.html
53
+ - doc/files/README_rdoc.html
54
+ - doc/files/lib/bitmask_attributes/definition_rb.html
55
+ - doc/files/lib/bitmask_attributes/value_proxy_rb.html
56
+ - doc/files/lib/bitmask_attributes/version_rb.html
57
+ - doc/files/lib/bitmask_attributes_rb.html
58
+ - doc/i/arrows.png
59
+ - doc/i/results_bg.png
60
+ - doc/i/tree_bg.png
61
+ - doc/index.html
62
+ - doc/js/highlight.pack.js
63
+ - doc/js/jquery-1.3.2.min.js
64
+ - doc/js/jquery-effect.js
65
+ - doc/js/main.js
66
+ - doc/js/navigation.js
67
+ - doc/js/search_index.js
68
+ - doc/js/searchdoc.js
69
+ - doc/js/searcher.js
70
+ - doc/panel/index.html
71
+ - doc/panel/links.html
72
+ - doc/panel/tree.js
40
73
  - lib/bitmask_attributes.rb
41
74
  - lib/bitmask_attributes/definition.rb
42
75
  - lib/bitmask_attributes/value_proxy.rb