Project

obfuscated

0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Obfuscate your autoincrementing primary key ids.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 2.3.0
 Project 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