As usually staging and production databases are different from each other, so testing new features on staging database can be painful because of lack of data, and diferrences of data.
Simple Rewriter enables ability to anonymize whole database with simply mappings, you can use dump production data to have production-like data on staging database without worrying about personal data.
gem install simple_rewriter
Or in gemfile
gem "simple_rewriter", "~> 0.0.2"
SimpleRewriter.call(
record: user,
attributes: [
:created_at,
{ token: :hex },
{ email_field: :email },
{ address_field: :address },
{ hash_field: [:deep, :detect_type] },
{ remote_file_urls: { sample_pdf: true, default: [] }, # carrierwave support
{ hash: [
:deep,
{
deep_attributes_map: [
{ zip: :zip },
{ street: :street },
{ name: [:first_name, :last_name] }
]
}
]
}
]
)
Options | Expected Output |
---|---|
[email protected] | |
:address | {:street=>"137 Fahey Street", :city=>"New Terryville", :zip=>"30752"} |
:hex | 6fe6a2485164f0 |
:name | Evie Upton |
:first_name | Evie |
:last_name | Upton |
:phonenumber | 333-333-3333 |
:zip | 58517 |
:street | 282 Kevin Brook |
:city | Imogeneborough |
:date | 1972-01-02 01:23:21 +0100 |
:sample_pdf | http://www.africau.edu/images/default/sample.pdf |
:deep | nil Only used to trigger rewriter to go deeper into record |
:deep_attributes_map | nil Used to map deeper attributes of record |
Options can be joined for e.g. passing [:first_name, :last_name]
will give the same as [:name]
Prevent rewriter from saving record
SimpleRewriter.configure do |config|
config.save = false
end
Custom seeds
SimpleRewriter.configure do |config|
config.integer_range = 0..10
config.hash_key_length = 5
config.rand_num_max = 10
config.address = nil # override default address generator as hash with values
end
Custom readers/writers
SimpleRewriter.configure do |config|
config.reader = SimpleRewriter::Reader
config.writer = SimpleRewriter::Writer
end
Sample Pdf url
SimpleRewriter.configure do |config|
config.sample_pdf_url = "http://www.africau.edu/images/default/sample.pdf"
end
Real anonymizer configured with sample mappings for batch updates.
We use PORO to keep dependieces clear and simple.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Running tests
bundle install
bin/rspec
Licensed under MIT by the Verivox GmbH