{"id":14956027,"url":"https://github.com/drbragg/redaction","last_synced_at":"2025-10-24T09:30:27.261Z","repository":{"id":39979032,"uuid":"468400528","full_name":"DRBragg/redaction","owner":"DRBragg","description":"Easily redact your ActiveRecord Models. Great for use when you use production data in staging or dev.","archived":false,"fork":false,"pushed_at":"2022-11-10T17:23:26.000Z","size":85,"stargazers_count":20,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-29T09:22:18.059Z","etag":null,"topics":["activerecord","rails","redaction","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"https://github.com/drbragg/redaction","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/DRBragg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-10T15:26:49.000Z","updated_at":"2024-10-12T01:08:30.000Z","dependencies_parsed_at":"2022-09-01T13:11:07.975Z","dependency_job_id":null,"html_url":"https://github.com/DRBragg/redaction","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DRBragg%2Fredaction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DRBragg%2Fredaction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DRBragg%2Fredaction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DRBragg%2Fredaction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DRBragg","download_url":"https://codeload.github.com/DRBragg/redaction/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237944057,"owners_count":19391588,"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","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","rails","redaction","ruby","ruby-on-rails"],"created_at":"2024-09-24T13:12:12.204Z","updated_at":"2025-10-24T09:30:26.904Z","avatar_url":"https://github.com/DRBragg.png","language":"Ruby","readme":"# Redaction\n[![Gem Version](https://badge.fury.io/rb/redaction.svg)](https://badge.fury.io/rb/redaction)\n[![Tests](https://github.com/DRBragg/redaction/actions/workflows/ci.yml/badge.svg)](https://github.com/DRBragg/redaction/actions/workflows/ci.yml)\n\nEasily redact your ActiveRecord Models. Great for use when you use production data in staging or dev. Simply set the redaction type of the attributes you want to redact and run via the [console](#via-the-rails-console) or the included [rake task](#via-rake-task).\n\n`redaction` uses [Faker](https://github.com/faker-ruby/faker) under the hood to generate redacted data.\n\n## Installation\n**NOTE:** This is currently very much in beta. Use at your own risk.\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"redaction\"\n```\n\nAnd then execute:\n```bash\n$ bundle install\n```\n\n## Usage\n### Redacting a Model\nTo \"redact\" a models attribute add:\n```ruby\nclass Model \u003c ApplicationRecord\n  redacts :\u003cattribute\u003e, with: :\u003credactor_type\u003e\nend\n```\n`\u003credactor_type\u003e` can be a symbol, proc, or custom class. See [Redactor Types](#redactor-types) for more information.\n\n`redacts` accepts multiple attributes, provided they all use the same redactor type. i.e.:\n```ruby\nclass User \u003c ApplicationRecord\n  redacts :first_name, :last_name, with: :name\nend\n```\n### Redactor Types\n\n#### Built in\n`redaction` comes with a few different redactor types:\n| Type         | Generates    |\n|:------------:|:------------:|\n| `:basic`     | A Sentence   |\n| `:basic_html`| An HTML snippet with `strong` and `em` tags wrapping some of the words  |\n| `:email`     | A safe (will not send) email address |\n| `:html`      | Multiple HTML Paragraphs with a random amount of link tags, `strong` tags, and `em` tags  |\n| `:name`      | A person first/last name |\n| `:phone`     | A phone number |\n| `:text`      | Multiple paragraphs |\n\nTo use a built in redactor type set the `with:` option of a `redacts` call to the appropriate symbol.\n\n#### Using a Proc\nA Proc `:with` value is given two arguments: the record being redacted, and a hash with the :attribute key-value pair.\n```ruby\nclass Model \u003c ApplicationRecord\n  redacts :attribute, with: -\u003e (record, data) { record.id }\nend\n```\nwould cause `Model#attribute` to be set to `Model#id` after redaction\n#### Using a custom class\nAdd a folder in `app/`, `redactors/` is suggested, and put custom redactors in there. A custom redactor should inherit from `Redaction::Types::Base` and should define a `content` method. Like so:\n```ruby\n# app/redactors/custom_redactor.rb\nclass CustomRedactor \u003c Redaction::Types::Base\n  def content\n    \"Some Custom Value\"\n  end\nend\n```\nand then to use it:\n```ruby\nclass Model \u003c ApplicationRecord\n  redacts :attribute, with: CustomRedactor\nend\n```\nwould cause `Model#attribute` to be set to \"Some Custom Value\" after redaction.\nCustom redactor types also get access to the record being redacted via `record`, and a hash with the `:attribute` key-value pair via `data`\n\n### Preforming a Redaction\nThere are two ways to preform the redaction.\n\n#### Via Rake Task\n```bash\nrails redaction:redact\n```\nThis will target **all** the models with redacted attributes. To target specific models run:\n```bash\nrails redaction:redact MODELS=User,Post\n```\nThis will only redact the `User` and `Post` Models\n\n#### Via the Rails Console\n```ruby\nRedaction.redact!\n```\nThis will target **all** the models with redacted attributes. To target specific models run:\n```ruby\nRedaction.redact!(models: [\"User\", \"Post\"])\n```\nThis will only redact the `User` and `Post` Models\n\n#### Validations and Callbacks\nBy default, preforming a redaction does not trigger validations or update the `updated_at` attribute.\n\nCallbacks can be skipped with the `:redacting?` method. i.e.:\n```ruby\nclass User \u003c ApplicationRecord\n  after_save :do_something, unless: :redacting?\n\n  redacts :first_name, :last_name, with: :name\nend\n```\n\n### Configuration\nRedaction has the following configuration options:\n| Option       | Default      | Description  |\n|:------------|:------------|:------------|\n| `email_domain`     | `nil`  | Set to a string to use a custom domain for redacted emails. i.e. `Redaction.config.email_domain = \"my-domain.dev\" |\n| `progress_bar`| `true`  | Set to false to not use the built in progress bar when redacting |\n| `force_redaction`     | `false` | Set to true to alway fill a column with redacted content even if the attribute is `nil` or empty |\n\nIt is reccomended that you put your configuration in an initializer like `config/initializers/redaction.rb`\n\n## Roadmap\n- [ ] Raise Error or at least a message when skipping a passed in Model\n- [ ] Configuration (touch, email domains, etc)\n- [ ] Better Documentation\n- [ ] More types\n- [ ] Release v1.0 as a real gem\n\n## Contributing\nBug reports and pull requests are welcome on GitHub at [drbragg/redaction](https://github.com/drbragg/redaction). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/DRBragg/redaction/blob/main/CODE_OF_CONDUCT.md).\n\n## License\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Acknowledgments\n`redaction` leans heavily on the awesome [Faker gem](https://github.com/faker-ruby/faker).  If not for their hard work this would be a much different and probably more complex project.  If you like `redaction` please consider sending them a thank you or contributing to the gem.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrbragg%2Fredaction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrbragg%2Fredaction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrbragg%2Fredaction/lists"}