makumba_import 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -0
- data/lib/makumba_import/importer.rb +2 -1
- data/lib/makumba_import/legacy.rb +41 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -37,3 +37,13 @@ MakumbaImport::Importer.setOutputPath "./" # where to generate the .rb files. Le
|
|
37
37
|
rake makumba_import:schema
|
38
38
|
rake makumba_import:models
|
39
39
|
```
|
40
|
+
|
41
|
+
Extra:
|
42
|
+
|
43
|
+
Use
|
44
|
+
|
45
|
+
```
|
46
|
+
SomeModel.first.toExternalForm
|
47
|
+
```
|
48
|
+
|
49
|
+
to get the makumba pointer
|
@@ -216,6 +216,7 @@ module MakumbaImport
|
|
216
216
|
txt << "class "+tablename.classify+" < ActiveRecord::Base\n"
|
217
217
|
txt << " set_table_name \""+tablename+"_\"\n"
|
218
218
|
txt << " set_primary_key \""+lastpart+"_\"\n"
|
219
|
+
txt << " set_makumba_pointer_type \""+key+"\"\n\n"
|
219
220
|
|
220
221
|
table.each do |name, field|
|
221
222
|
if name == 'ref'
|
@@ -231,7 +232,7 @@ module MakumbaImport
|
|
231
232
|
end
|
232
233
|
end
|
233
234
|
|
234
|
-
txt << " fix_makumba_columns\n
|
235
|
+
txt << "\n fix_makumba_columns\n"
|
235
236
|
|
236
237
|
txt << "end\n\n"
|
237
238
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module LegacyMakumba
|
2
|
+
|
2
3
|
def self.append_features(base)
|
3
4
|
super
|
4
5
|
base.extend(ClassMethods)
|
@@ -15,9 +16,48 @@ module LegacyMakumba
|
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
19
|
+
|
20
|
+
def set_makumba_pointer_type(type)
|
21
|
+
self.send(:define_method, "pointer_type") { type }
|
22
|
+
end
|
18
23
|
end
|
24
|
+
|
25
|
+
def toExternalForm
|
26
|
+
def crc(v)
|
27
|
+
r = 0
|
28
|
+
32.times do
|
29
|
+
if (v & 1) == 1
|
30
|
+
r = r + 1
|
31
|
+
end
|
32
|
+
v = v >> 1;
|
33
|
+
end
|
34
|
+
r
|
35
|
+
end
|
36
|
+
|
37
|
+
# http://www.func09.com/wordpress/archives/228
|
38
|
+
def to_hashcode(str)
|
39
|
+
max = 2 ** 31 - 1
|
40
|
+
min = -2 ** 31
|
41
|
+
h = 0
|
42
|
+
n = str.size
|
43
|
+
n.times do |i|
|
44
|
+
h = 31 * h + str[i].ord
|
45
|
+
while h < min || max < h
|
46
|
+
h = max - ( min - h ) + 1 if h < min
|
47
|
+
h = min - ( max - h ) - 1 if max < h
|
48
|
+
end
|
49
|
+
end
|
50
|
+
h
|
51
|
+
end
|
52
|
+
|
53
|
+
n = self.id
|
54
|
+
|
55
|
+
hc = to_hashcode(pointer_type) & "ffffffffl".to_i(16)
|
56
|
+
((crc(n) & "fl".to_i(16)) << 32 | n ^ hc).to_s(36)
|
57
|
+
end
|
58
|
+
|
19
59
|
end
|
20
60
|
|
21
|
-
ActiveRecord::Base
|
61
|
+
class ActiveRecord::Base
|
22
62
|
include LegacyMakumba
|
23
63
|
end
|