Created
February 20, 2012 20:09
-
-
Save adarsh/1871104 to your computer and use it in GitHub Desktop.
Code from blog post on anonymizing sensitive user data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :env_checker do | |
unless Rails.env.development? | |
puts "Not in development environment, exiting!" | |
exit 1 | |
end | |
end | |
namespace :app_name do | |
desc 'Anonymize user, company, and location information' | |
task :anonymize => [:environment, :env_checker] do | |
User.all.each do |user| | |
genders = ['male', 'female'] | |
user.update_attributes!( | |
:born_on => rand(50*365).days.ago | |
:email => (rand(1000) + 100).to_s + Faker::Internet.email, | |
:first_name => Faker::Name.first_name, | |
:gender => genders.rand, | |
:last_name => Faker::Name.last_name) | |
end | |
Company.all.each do |company| | |
company.update_attributes!( | |
:description_html => Faker::Company.catch_phrase, | |
:name => Faker::Company.name, | |
:twitter_username => Faker::Internet.user_name, | |
:url => 'http://' + Faker::Internet.domain_name) | |
end | |
location_array = Location.all.inject([]) do |result, location| | |
result << [location.lat, location.lng] | |
end.shuffle | |
Location.all.each do |location| | |
lat, lng = location_array.pop | |
location.update_attributes( | |
:city => Faker::Address.city, | |
:extended_address => Faker::Address.secondary_address, | |
:lat => lat, | |
:lng => lng, | |
:phone => Faker::PhoneNumber.phone_number, | |
:postal_code => Faker::Address.zip_code, | |
:state => Faker::Address.state_abbr, | |
:street_address => Faker::Address.street_address | |
) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To generate your own phone format, you can use Faker.numerify("###-###-####")
See more at https://github.com/yyyc514/faker/blob/master/lib/faker/phone_number.rb#L5