{"id":31661713,"url":"https://github.com/jamesstonehill/anonymous","last_synced_at":"2025-10-07T19:02:37.539Z","repository":{"id":56842443,"uuid":"161915326","full_name":"jamesstonehill/anonymous","owner":"jamesstonehill","description":"Data anonymization for ActiveRecord","archived":false,"fork":false,"pushed_at":"2019-12-30T18:16:58.000Z","size":20,"stargazers_count":1,"open_issues_count":7,"forks_count":4,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-07T19:02:05.966Z","etag":null,"topics":["activerecord","data-anonymization","gem","rails","ruby","rubygem"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamesstonehill.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-15T14:58:17.000Z","updated_at":"2021-02-02T08:28:48.000Z","dependencies_parsed_at":"2022-08-29T07:41:59.535Z","dependency_job_id":null,"html_url":"https://github.com/jamesstonehill/anonymous","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jamesstonehill/anonymous","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesstonehill%2Fanonymous","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesstonehill%2Fanonymous/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesstonehill%2Fanonymous/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesstonehill%2Fanonymous/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamesstonehill","download_url":"https://codeload.github.com/jamesstonehill/anonymous/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesstonehill%2Fanonymous/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278830041,"owners_count":26053223,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","data-anonymization","gem","rails","ruby","rubygem"],"created_at":"2025-10-07T19:01:24.904Z","updated_at":"2025-10-07T19:02:37.534Z","avatar_url":"https://github.com/jamesstonehill.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Anonymous\n[![Gem Version](https://badge.fury.io/rb/anonymous.svg)](https://badge.fury.io/rb/anonymous)\n[![Build Status](https://travis-ci.org/jamesstonehill/anonymous.svg?branch=master)](https://travis-ci.org/jamesstonehill/anonymous)\n\nAnonymous is a light-weight gem that makes anonymizing ActiveRecord models easy!\nRemember, friends don't let friends use production data in\nstaging/development.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'anonymous'\n```\n\nAnd then execute:\n\n    $ bundle\n\n## Usage\n\n### Usage With ActiveRecord\nTo use this gem in your ActiveRecord models you need to do two things.\n1. Include the `Anonymous::ActiveRecord` module in your model\n2. Define a private method `anonymization_definitions` with the anonymization\n   definitions inside it.\n\n```ruby\nclass User \u003c ApplicationRecord\n  include Anonymous::ActiveRecord\n\n  private\n\n  def anonymization_definitions\n    {\n      name: [\"Bob Dylan\", \"Tony Blair\"].sample,\n      email: -\u003e (user_email) { \"fake_#{user_email}\" },\n      phone_number: -\u003e (phone) { phone[0..-4] + 3.times.map{rand(10)}.join },\n    }\n  end\nend\n```\n\nThe return value of `anonymization_definitions` should be a Hash where the keys\nare the names of the attribute to be anonymized and the values are either a\n`Proc` object or the value to be filled in for the anonymized attribute.\n\nIf you use a proc or lambda as the argument then the attribute value will be\nprovided to you in the proc's first argument. This is useful when you want your\nanonymized value to be a transformation of the original.\n\nIt is recommended that you use this gem in conjunction with a fake data\ngeneration library like [faker](https://github.com/stympy/faker).\n\n```ruby\n  def anonymization_definitions\n    {\n      first_name: Faker::Name.first_name,\n      email: Faker::Internet.unique.email,\n    }\n  end\n```\n\nThen when you have set up the gem correctly you can call `anonymize` and\n`anonymize!` on the model.\n\n```ruby\nuser = User.create(\n  name: \"John Smith\",\n  email: \"john.smith@example.com\",\n  phone_number: \"+447875477389\"\n)\nuser.anonymize! # or user.anonymize\nuser.reload\nuser.email\n=\u003e \"fake_john.smith@example.com\"\nuser.name\n=\u003e \"Bob Dylan\"\nuser.phone_number\n=\u003e \"+447875477412\"\n```\n\nThe only difference between `anonymize!` and `anonymize` is that the former\ncalls `update_attributes!` and the latter calls `update_attributes`.\n\n## Configuration\n\nYou can configure the gem to alter the anonymisation behaviour.\n\n```ruby\n# config/initializers/anonymous.rb\n\nAnonymous.configure do |config|\n  config.max_anonymize_retries = 0\nend\n```\n\n### Configuration Options\n\n1. max_anonymize_retries\nUnder some situations (like if an RecordNotUnique error is raised when updating)\nthe gem will retry the anonymization process. By default it will only do this\nonce.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run\n`bundle exec rake appraisal spec` to run the tests. You can also run\n`bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`.\n\nTo release a new version, update the version number in `version.rb`, then run\n`bundle install` and `bundle exec appraisal install`, and finally run `bundle\nexec rake release`, which will create a git tag for the version, push git\ncommits and tags, and push the `.gem` file to\n[rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at\nhttps://github.com/jamesstonehill/anonymous.\n\nSome ideas for feature contributions:\n- Support for ORMs other than ActiveRecord.\n- More comprehensive retry functionality in Anonymous::ActiveRecord. A the\n    moment we only retry if we get an ActiveRecord::RecordNotUnique unique\n    error. I didn't want to blindly rescue all errors, but it seems like that\n    there are other times we would want to retry.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT\nLicense](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesstonehill%2Fanonymous","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesstonehill%2Fanonymous","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesstonehill%2Fanonymous/lists"}