{"id":13879441,"url":"https://github.com/maximeg/activecleaner","last_synced_at":"2025-04-13T19:32:29.702Z","repository":{"id":6593300,"uuid":"7836094","full_name":"maximeg/activecleaner","owner":"maximeg","description":"Field cleaner for models in Ruby on Rails. Strips extra spaces among other things.","archived":false,"fork":false,"pushed_at":"2022-02-14T10:46:51.000Z","size":71,"stargazers_count":13,"open_issues_count":4,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T10:11:16.793Z","etag":null,"topics":["rails","ruby"],"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/maximeg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-26T10:05:23.000Z","updated_at":"2023-02-26T11:14:35.000Z","dependencies_parsed_at":"2022-09-15T16:21:50.204Z","dependency_job_id":null,"html_url":"https://github.com/maximeg/activecleaner","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/maximeg%2Factivecleaner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximeg%2Factivecleaner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximeg%2Factivecleaner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximeg%2Factivecleaner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maximeg","download_url":"https://codeload.github.com/maximeg/activecleaner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248767803,"owners_count":21158532,"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":["rails","ruby"],"created_at":"2024-08-06T08:02:21.217Z","updated_at":"2025-04-13T19:32:29.636Z","avatar_url":"https://github.com/maximeg.png","language":"Ruby","readme":"# ActiveCleaner\n\n[![Gem Version](https://badge.fury.io/rb/activecleaner.svg)](https://rubygems.org/gems/activecleaner)\n[![Build Status](https://travis-ci.org/maximeg/activecleaner.svg?branch=master)](https://travis-ci.org/maximeg/activecleaner)\n\n`ActiveCleaner` is a set of helpers that helps you in cleaning user-typed content in your ActiveModel depending models (ActiveRecord, Mongoid...)\n\nExtra spaces mean extra storage. And it could ruin your indexes and your sortings.\n\nTired of doing everywhere:\n\n```ruby\nbefore_validation :clean_title\n\ndef clean_title\n  unless title.nil?\n    self.title = title.squish\n  end\n  self.title = nil if title.blank?\n\n  true\nend\n```\n\n### Cleaners included\n\n- `:string` (StringCleaner, the default one) : cleans all the space characters. It turns `\" A \\n \\t title \\t \"` into `\"A title\"`.\n- `:text` (TextCleaner) : like `:string`, but preserves new lines (with a max of 2 successive new lines). useful when the field is rendered with the `simple_format` Rails helper.\n- `:markdown` (MarkdownCleaner) : like `:text`, but preserves spaces in the beginning of lines (the indentation). useful for... markdown!\n- `:utf8mb3` (Utf8mb3Cleaner) : removes all 4-bytes encoded chars in UTF8 strings that mess with the `utf8` encoding in MySQL (iOS6 emojis for example).\n\n## Installation\n\nAdd the gem to your Gemfile:\n\n    gem 'activecleaner'\n\nOr install with RubyGems:\n\n    $ gem install activecleaner\n\n## Usage\n\n### Basic usage\n\nAdd `include ActiveCleaner` in your model and also do:\n\n```ruby\nclean :field_1, :field_2 ... :field_n, options_1: :value, options_2: :value\n```\n\n### Options\n\n- `:as` (default is `:string`) : the symbol name of the cleaner.\n- `:nilify` (default is `false`) : set to `nil` when the field was or is cleaned to `\"\"`.\n\n### Example\n\n```ruby\nclass Post\n  include Mongoid::Document\n  include ActiveCleaner\n\n  field :title\n  field :subtitle\n  clean :title, :subtitle, nilify: true\n\n  field :body\n  clean :body, as: :text, nilify: true\nend\n```\n\n## Contributing\n\nContributions and bug reports are welcome.\n\nClone the repository and run `bundle install` to setup the development environment.\n\nProvide a case spec according to your changes/needs, taking example on existing ones (in `spec/cases`).\n\nTo run the specs:\n\n    bundle exec rspec\n\nYou can also use `guard` to run the specs during dev.\n\n## Credits\n\n- Maxime Garcia [emaxime.com](http://emaxime.com) [@maximegarcia](http://twitter.com/maximegarcia)\n\n[License](https://github.com/maximeg/activecleaner/blob/master/LICENSE)\n\\- [Report a bug](https://github.com/maximeg/activecleaner/issues)\n\\- [Rubygems page](https://rubygems.org/gems/activecleaner)\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximeg%2Factivecleaner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaximeg%2Factivecleaner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximeg%2Factivecleaner/lists"}