strip_attributes
strip_attributes copied to clipboard
:hocho: An ActiveModel extension that automatically strips all attributes of leading and trailing whitespace before validation. If the attribute is blank, it strips the value to nil.
When doing operations on lots of models, strip_attributes can be responsible for a lot of small allocations for strings and regexes that do not change, but are nonetheless re-allocated every...
Related to #34. Investigate and perhaps consider using the new attributes API instead of a `before_validation` callback. ```ruby class Strippable < ActiveRecord::Type::String def cast_value(value) value.to_s.strip end end class Something <...
Similar idea as #43 Investigate and perhaps consider using the [new normalizes API in Rails 7.1](https://guides.rubyonrails.org/7_1_release_notes.html#add-activerecord-base-normalizes) instead of a before_validation callback. This would result in a major version bump for...
This allows the gem to support `ActiveModel::Model` as well as `ActiveRecord`.
We had a bug with frozen Strings. It's not clear that the stripping was also mutating, and it was failing silently on the frozen String. I figure there are basically...
It would be good to don't strip on binary columns (@sql_type="mediumblob", @type=:binary). I had the callback added to ApplicationRecord, and had "invalid byte sequence in UTF-8" error on a binary...
This snippet should return `nil`, since its given a blank string and `allow_empty: false` ```ruby StripAttributes.strip(String(nil), allow_empty: false) # => "" ``` The reason is this guard against frozen strings:...
I recently updated to the latest version (2.0.0), and in our app we use this gem on some POROs. Here's an example of how we use it: ``` class PatientForm...
I hope you are doing well. Thank you for all the hard work you’ve put into maintaining this gem. I noticed that there have been several commits merged into the...