{"id":13880083,"url":"https://github.com/fnando/normalize_attributes","last_synced_at":"2025-09-11T13:32:02.199Z","repository":{"id":787624,"uuid":"483717","full_name":"fnando/normalize_attributes","owner":"fnando","description":"Sometimes you want to normalize data before saving it to the database like down casing e-mails, removing spaces and so on. This Rails plugin allows you to do so in a simple way.","archived":false,"fork":false,"pushed_at":"2023-09-05T11:43:44.000Z","size":63,"stargazers_count":49,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-01T22:11:50.692Z","etag":null,"topics":["activerecord","normalization","rails"],"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/fnando.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["fnando"],"custom":["https://paypal.me/fnando/🍕"]}},"created_at":"2010-01-22T11:51:44.000Z","updated_at":"2023-07-06T15:01:15.000Z","dependencies_parsed_at":"2024-10-20T12:40:03.689Z","dependency_job_id":null,"html_url":"https://github.com/fnando/normalize_attributes","commit_stats":{"total_commits":47,"total_committers":6,"mean_commits":7.833333333333333,"dds":0.3829787234042553,"last_synced_commit":"f76f829d462df73d4b1f809792c3f804184e3b6f"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fnormalize_attributes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fnormalize_attributes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fnormalize_attributes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fnormalize_attributes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnando","download_url":"https://codeload.github.com/fnando/normalize_attributes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232651122,"owners_count":18555934,"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","normalization","rails"],"created_at":"2024-08-06T08:02:46.545Z","updated_at":"2025-01-05T23:10:21.820Z","avatar_url":"https://github.com/fnando.png","language":"Ruby","readme":"# Normalize Attributes\n\n[![Tests](https://github.com/fnando/normalize_attributes/workflows/ruby-tests/badge.svg)](https://github.com/fnando/normalize_attributes)\n[![Code Climate](https://codeclimate.com/github/fnando/normalize_attributes/badges/gpa.svg)](https://codeclimate.com/github/fnando/normalize_attributes)\n[![Gem](https://img.shields.io/gem/v/normalize_attributes.svg)](https://rubygems.org/gems/normalize_attributes)\n[![Gem](https://img.shields.io/gem/dt/normalize_attributes.svg)](https://rubygems.org/gems/normalize_attributes)\n\nSometimes you want to normalize data before saving it to the database like\ndowncasing e-mails, removing spaces and so on. This Rails plugin allows you to\ndo so in a simple way.\n\n## Usage\n\nTo install:\n\n    gem install normalize_attributes\n\nThen on your model:\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  normalize :email, with: :downcase\nend\n```\n\nThe example above will normalize your `:email` attribute on the `before_save`\ncallback.\n\nYou can specify multiple attributes\n\n```ruby\nnormalize :email, :username, with: :downcase\n```\n\nYou can use a block\n\n```ruby\nnormalize :name do |value|\n  value.squish\nend\n```\n\nYou can combine both\n\n```ruby\nnormalize :name, with: :downcase do |value|\n  value.squish\nend\n```\n\nThe `squish` method is the default normalizer for strings. All you need to is\nspecify the attribute:\n\n```ruby\nnormalize :content\n```\n\nThe `compact` method is the default normalizer for arrays (when using\n`serialize` method):\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  serialize :preferences, Array\n  normalize :preferences\nend\n```\n\nThe `normalize` method is aliased as `normalize_attributes`,\n`normalize_attribute`, `normalize_attr`, and `normalize_attrs`.\n\nYou can normalize the attribute before type casting; this is specially useful\nfor normalizing dates and numbers.\n\n```ruby\nclass Product\n  normalize(:price, raw: true) {|v| Money.new(v).to_f }\nend\n```\n\nYou can also use it with `ActiveModel::Model` classes.\n\n```ruby\nclass UserForm\n  include ActiveModel::Model\n  include ActiveModel::Attributes\n  include ActiveModel::Validations::Callbacks\n  include NormalizeAttributes::Callbacks\n\n  attribute :username\n  normalize :username\nend\n```\n\n## Maintainer\n\n- [Nando Vieira](https://github.com/fnando)\n\n## Contributors\n\n- https://github.com/fnando/normalize_attributes/contributors\n\n## Contributing\n\nFor more details about how to contribute, please read\nhttps://github.com/fnando/normalize_attributes/blob/main/CONTRIBUTING.md.\n\n## License\n\nThe gem is available as open source under the terms of the\n[MIT License](https://opensource.org/licenses/MIT). A copy of the license can be\nfound at https://github.com/fnando/normalize_attributes/blob/main/LICENSE.md.\n\n## Code of Conduct\n\nEveryone interacting in the normalize_attributes project's codebases, issue\ntrackers, chat rooms and mailing lists is expected to follow the\n[code of conduct](https://github.com/fnando/normalize_attributes/blob/main/CODE_OF_CONDUCT.md).\n","funding_links":["https://github.com/sponsors/fnando","https://paypal.me/fnando/🍕"],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fnormalize_attributes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnando%2Fnormalize_attributes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fnormalize_attributes/lists"}