Module: Obfuscated::InstanceMethods

Defined in:
lib/obfuscated.rb

Instance Method Summary collapse

Instance Method Details

#hashed_idObject

Generate an obfuscated 12 character id incorporating the primary key and the table name.



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/obfuscated.rb', line 61

def hashed_id
  raise 'This record does not have a primary key yet!' if id.blank?
  
  # If Obfuscated isn't supported, just return the normal id
  return id unless Obfuscated::supported?
  
  # Use SHA1 to generate a consistent hash based on the id and the table name
  @hashed_id ||= Digest::SHA1.hexdigest(
    "---#{id}-WICKED-#{self.class.table_name}-#{Obfuscated::salt}"
  )[0..11]  
end

#to_paramObject



73
74
75
# File 'lib/obfuscated.rb', line 73

def to_param
  hashed_id
end