Obfuscate the primary keys of ActiveRecord objects
Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
test
README
obfuscated.gemspec

README

Obfuscated
==============

Obfuscated allows you to obfuscate the primary keys of your ActiveRecord models
which use autoincrementing integer ids. Currently only works with MySQL.

Just add "obfuscated" to your Gemfile!

Example
=======

class User < ActiveRecord::Base
  has_obfuscated_id
end

@user = User.first
@user.id
# 1
@user.hashed_id
# "9b46a2e8c9db"
@user.to_param
# "9b46a2e8c9db"

@same_user = User.find_by_hashed_id( "9b46a2e8c9db" )

Obfuscated will try to find the record using its obfuscated id when you
pass a 12 digit string to find() :
@same_user = User.find( "9b46a2e8c9db" )
@same_user = User.find( 1 )

As of 0.1.6, ActiveRelations also work:
User.includes(:posts).find( "9b46a2e8c9db" )


Configuration
=======
Set a salt for your app by adding initializers/obfuscated.rb:
 Obfuscated.salt = 'somerandomstringofcharacters'

Copyright (c) 2008 Jon Collier, released under the MIT license