Skip to content

Instantly share code, notes, and snippets.

@jkappers
Created May 27, 2014 22:56
Show Gist options
  • Save jkappers/94399bd2b2bab0934e77 to your computer and use it in GitHub Desktop.
Save jkappers/94399bd2b2bab0934e77 to your computer and use it in GitHub Desktop.
Simple rake task for obfuscating data in a small rails app.
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