README.md in sanitization-1.0.2 vs README.md in sanitization-1.1.0
- old
+ new
@@ -1,24 +1,48 @@
# Sanitization
Sanitization makes it easy to store slightly cleaner strings to your database.
+
### Features (all optional):
- White space stripping
- White space collapsing (multiple consecutive spaces combined into one)
- Empty string to nil (if database column supports it)
- Change casing (ie. upcase, downcase, titlecase, etc)
+
### Defaults
-- Leading & training white spaces are stripped (`strip: true`)
-- All spaces are collapsed (`collapse: true`)
-- All empty strings are stored as `null` if the database column allows it (`nullify: true`)
+By default, Sanitization has all options disabled. It is recommended you use a configuration block to set
+sensitive defaults for your projects.
+
+For example, I use:
+
+```ruby
+# config/initializers/sanitization.rb
+
+Sanitization.configure do |config|
+ config.strip = true
+ config.collapse = true
+ config.nullify = true
+end
+
+# or you can use the following shortcut instead:
+
+Sanitization.simple_defaults!
+```
+
+
+### Configuration Options
+
+- Strip leading & training white spaces (`strip: true|false`)
+- Collapse consecutive spaces (`collapse: true|false`)
+- Store empty strings as `null` if the database column allows it (`nullify: true|false`)
- All String columns are sanitized (`only: nil, except: nil`)
-- Columns of type `text` are not sanitized (`include_text_type: false`)
-- Casing remains unchanged (`case: nil`)
+- Also sanitize strings of type `text` (`include_text_type: true|false`)
+- Change casing: (`case: :none|:up|:down|:custom`)
## Installation
```sh
@@ -27,10 +51,18 @@
## Usage
```ruby
+
+# Assuming the following configuration block:
+Sanitization.configure do |config|
+ config.strip = true
+ config.collapse = true
+ config.nullify = true
+end
+
# Default settings for all strings
class Person < ApplicationModel
sanitization
# is equivalent to:
sanitization strip: true, collapse: true, include_text_type: false
@@ -68,12 +100,14 @@
sanitization only: '1337', case: :leet, nullify: false
end
```
+
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
+
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).