0.0
No commit activity in last 3 years
No release in over 3 years
Simple rewriter for rails based apps
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.12.2
~> 12.3.2
~> 3.8.0

Runtime

~> 1.9.3
 Project Readme

Gem Version CircleCI

Simple Rewriter

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.

Instalation

gem install simple_rewriter

Or in gemfile

gem "simple_rewriter", "~> 0.0.2"

Sample usage:

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 eac94f-example@domain.com
: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]

Configuration

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

Examples

Real anonymizer configured with sample mappings for batch updates.

Contributing

We use PORO to keep dependieces clear and simple.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Running tests

bundle install
bin/rspec

Authors

jcapt  ·  PiotrMisiurek  ·  michalsz


Licensed under MIT by the Verivox GmbH