{"id":15603238,"url":"https://github.com/ccocchi/activerecord-normalizations","last_synced_at":"2025-09-20T08:39:28.818Z","repository":{"id":59150373,"uuid":"379197554","full_name":"ccocchi/activerecord-normalizations","owner":"ccocchi","description":"Normalize your ActiveRecord models' attributes","archived":false,"fork":false,"pushed_at":"2022-04-11T21:58:51.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-24T10:13:15.144Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ccocchi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-22T08:31:58.000Z","updated_at":"2022-04-11T10:47:31.000Z","dependencies_parsed_at":"2022-09-13T11:00:24.750Z","dependency_job_id":null,"html_url":"https://github.com/ccocchi/activerecord-normalizations","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/ccocchi%2Factiverecord-normalizations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccocchi%2Factiverecord-normalizations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccocchi%2Factiverecord-normalizations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccocchi%2Factiverecord-normalizations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ccocchi","download_url":"https://codeload.github.com/ccocchi/activerecord-normalizations/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142074,"owners_count":20890653,"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":[],"created_at":"2024-10-03T03:02:07.916Z","updated_at":"2025-09-20T08:39:28.701Z","avatar_url":"https://github.com/ccocchi.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActiveRecord::Normalizations\n\n`ActiveRecord::Normalizations` gives you the possibility to transform, or normalize, your attributes before they are saved in your database. It behaves mostly like validations, applying normalizations in methods like `save` or `update` but being totally skipped when methods touching directly the database like `update_columns`.\n\n## Compatibility\n\n### Ruby\n\nCurrently supported Ruby versions: MRI 2.5, 2.6, 2.7, 3.0.\nJRuby hasn't been tested but since it's purely Ruby, it should work fine with it.\n\n### Rails\n\nAny version of ActiveRecord \u003e= 4.2. It is tested against AR 5.2, 6.0, 6.1\n\n## Installation\n\n```ruby\ngem 'activerecord-normalizations'\n```\n\n## Usage\n\n`ActiveRecord::Normalizations` is included in `ActiveRecord::Base` by default so you can directly use the `normalize` method in your models:\n\n```ruby\nclass User\n  normalizes :firstname, spaces: true, text_transform: :capitalize\nend\n```\n\nThe first argument is the attribute you want to normalize, and each subsequent option are the normalizers that are going to me applied to it, each with their option (much like ActiveRecord'd validations).\n\n## Normalizers\n\nThe gem comes with the following normalizers:\n\n### Spaces\n\nAvailable mode: `:leading, :trailing, :both (default)`\n\nThis normalizer removes leading, trailing or both spaces from your attribute. It uses Ruby's `strip` methods family under the hood.\n\n### TextTransform\n\nAvailable mode: `:capitalize, :lowercase, :uppercase, :word_capitalize`\n\nThis normalizer transforms your string attribute per the given mode:\n\n* `capitalize`, `lowercase` and `uppercase` are pretty straight-forward and use Ruby's equivalent methods\n* `word_capitalize` will capitalize every word of a string, a word being 1 or more alpha characters. Useful when dealing with foreign names like `Jean-Michel` or `O'Connor`.\n\n## Custom Normalizer\n\nYou can also define your own normalizers. They should be classes following the naming format `\u003coption_name\u003eNormalizer`, initialized with an options hash and responding to the `call` method with a single argument, the attribute to normalize.\n\nFor example, if you wanted to reverse your attribute you could do create the following class\n\n```ruby\n# app/normalizers/reverse_normalizer.rb\nclass ReverseNormalizer\n  def initialize(*args)\n  end\n\n  def call(attr)\n    attr.reverse\n  end\nend\n```\n\nthen use it in your model like any other normalizer\n\n```ruby\n# app/models/user.rb\nclass User \u003c ApplicationRecord\n  normalizes :name, reverse: true\nend\n```\n\nYou can check the [normalizers](https://github.com/ccocchi/activerecord-normalizations/tree/main/lib/activerecord-normalizations/normalizers) folder to see how included normalizers are done.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ccocchi/activerecord-normalizations. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the ActiveRecord::Normalizations project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ccocchi/activerecord-normalizations/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccocchi%2Factiverecord-normalizations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fccocchi%2Factiverecord-normalizations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccocchi%2Factiverecord-normalizations/lists"}