30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/obfuscated.rb', line 30
def has_obfuscated_id( options={} )
class_eval do
include Obfuscated::InstanceMethods
def self.find_by_hashed_id( hash, options={} )
return nil if hash.blank?
return find_by_id(hash, options) unless Obfuscated::supported?
options.update(:conditions => ["SUBSTRING(SHA1(CONCAT('---',#{self.table_name}.id,'-WICKED-#{self.table_name}-#{Obfuscated::salt}')),1,12) = ?", hash])
first(options) or raise ActiveRecord::RecordNotFound, "Couldn't find #{self.class.to_s} with Hashed ID=#{hash}"
end
end
end
|