10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/acts_as_having_string_id.rb', line 10
def acts_as_having_string_id(options = {})
class_eval do
attrib_type = ActsAsHavingStringId::StringId::Type.new(self)
attribute :id, attrib_type
self.reflections.each_value do |r|
unless r.is_a? ActiveRecord::Reflection::ThroughReflection
r.klass.class_eval do
attribute r.foreign_key.to_sym, attrib_type
end
end
end
def self.id_string(id)
_tea.encrypt(id).base62_encode
end
def self.id_int(id_string)
begin
id_int = id_string.base62_decode
rescue
return nil
end
_tea.decrypt(id_int)
end
end
end
|