Skip to content

Instantly share code, notes, and snippets.

@remvee
Created February 6, 2010 13:36
Show Gist options
  • Save remvee/296720 to your computer and use it in GitHub Desktop.
Save remvee/296720 to your computer and use it in GitHub Desktop.
make all email address in datamodel @example.com addresses
namespace :anonymize do
desc "Replace all email addresses by an example.com variant."
task :email => :environment do
ActiveRecord::Base.connection.tables.map(&:singularize).map(&:camelize).map do |m|
m.constantize rescue nil
end.compact.select do |m|
m.column_names.include?("email")
end.each do |m|
m.all.each do |v|
v.update_attribute(:email, "#{v.email.sub('@', '-')}@example.com") unless v.email.blank? || v.email =~ /@example.com$/
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment