Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/makumba_import/legacy.rb
Class Method Summary collapse
- .find_by_id(id) ⇒ Object
- .find_by_ptr(ptr) ⇒ Object
- .fix_makumba_columns ⇒ Object
- .last_primary_key(dbsv = MakumbaImport::KeyHandler.get_dbsv) ⇒ Object
- .metaclass ⇒ Object
- .next_primary_key ⇒ Object
- .pointer_type ⇒ Object
- .pointer_type=(type) ⇒ Object
Instance Method Summary collapse
Class Method Details
.find_by_id(id) ⇒ Object
44 45 46 |
# File 'lib/makumba_import/legacy.rb', line 44 def self.find_by_id(id) self.find(id) end |
.find_by_ptr(ptr) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/makumba_import/legacy.rb', line 36 def self.find_by_ptr(ptr) hc = @pointer_type.to_java_hashcode & "ffffffffl".to_i(16) l = ptr.to_i(36) n = l & "ffffffffl".to_i(16) n = n ^ hc self.find(n) end |
.fix_makumba_columns ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/makumba_import/legacy.rb', line 48 def self.fix_makumba_columns column_names.each do |old_name| if old_name.match(/_$/) new_name = old_name[0...-1] unless self.method_defined? new_name self.send(:define_method, new_name) { self.send(old_name) } self.send(:define_method, "#{new_name}=") { |value| self.send("#{old_name}=", value) } self..send(:define_method, "find_by_#{new_name}") { |value| self.send("find_by_#{old_name}", value) } self..send(:define_method, "find_by_#{new_name}!") { |value| self.send("find_by_#{old_name}!", value) } end end end self.send(:before_save, :update_makumba_fields) end |
.last_primary_key(dbsv = MakumbaImport::KeyHandler.get_dbsv) ⇒ Object
24 25 26 |
# File 'lib/makumba_import/legacy.rb', line 24 def self.last_primary_key(dbsv = MakumbaImport::KeyHandler.get_dbsv) self.select("max(#{primary_key}) as biggest").where("#{primary_key} > ? and #{primary_key} < ?", dbsv << 24, (dbsv + 1) << 24).first.biggest || (dbsv << 24) end |
.metaclass ⇒ Object
20 21 22 |
# File 'lib/makumba_import/legacy.rb', line 20 def self. class << self; self; end end |
.next_primary_key ⇒ Object
64 65 66 |
# File 'lib/makumba_import/legacy.rb', line 64 def self.next_primary_key MakumbaImport::KeyHandler.next_primary_key(self.to_s) end |
.pointer_type ⇒ Object
32 33 34 |
# File 'lib/makumba_import/legacy.rb', line 32 def self.pointer_type @pointer_type end |
.pointer_type=(type) ⇒ Object
28 29 30 |
# File 'lib/makumba_import/legacy.rb', line 28 def self.pointer_type=(type) @pointer_type = type end |
Instance Method Details
#crc(v) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/makumba_import/legacy.rb', line 75 def crc(v) r = 0 32.times do if (v & 1) == 1 r = r + 1 end v = v >> 1; end r end |
#to_ptr ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/makumba_import/legacy.rb', line 74 def to_ptr def crc(v) r = 0 32.times do if (v & 1) == 1 r = r + 1 end v = v >> 1; end r end n = self.id hc = self.class.pointer_type.to_java_hashcode & "ffffffffl".to_i(16) ((crc(n) & "fl".to_i(16)) << 32 | n ^ hc).to_s(36) end |
#update_makumba_fields ⇒ Object
68 69 70 71 72 |
# File 'lib/makumba_import/legacy.rb', line 68 def update_makumba_fields self.id = self.class.next_primary_key if self.id.blank? self.TS_create = Time.new if self.TS_create.blank? self.TS_modify = Time.new end |