Created
May 27, 2014 22:56
-
-
Save jkappers/94399bd2b2bab0934e77 to your computer and use it in GitHub Desktop.
Simple rake task for obfuscating data in a small rails app.
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
class Scrubber | |
VALUE_PROVIDERS = { | |
"name" => Proc.new { Faker::Name.name }, | |
"email" => Proc.new { Faker::Internet.email }, | |
"ssn" => Proc.new { rand.to_s[2..10] } | |
} | |
def scrub(*classes) | |
classes.each do |klass| | |
klass.all.each { |model| fake(model) } | |
end | |
end | |
def fake(model) | |
VALUE_PROVIDERS.each do |key, method| | |
model.send("#{key}=", method.call) if model.respond_to?("#{key}=") | |
model.save | |
end | |
end | |
end | |
namespace :data do | |
task :scrub => :environment do | |
scrubber = Scrubber.new | |
scrubber.scrub(User) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment