Created
February 6, 2010 13:36
-
-
Save remvee/296720 to your computer and use it in GitHub Desktop.
make all email address in datamodel @example.com addresses
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
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