validates_not_profane

DESCRIPTION:

validates_not_profane provides a hook into the Profanalyzer gem as a validation for your ActiveRecord models. It's use is simple:

validates_not_profane :column_name, :column_2

Will cause the model to produce errors if that column contains profanity in its value. Of course, since the Profanalyzer gem is customizable, so is the validation:

validates_not_profane :post_title, :racist => true, :sexual => false

will block racial slurs, but nothing else.

validates_not_profane :post_title, :tolerance => 5

will block only the most vile of profanity. The scale for tolerance is from 0-5, which is mostly subjective, in all honesty.

You can also use the :label option to customize the error message - see the examples below.

FEATURES/PROBLEMS:

  • Tolerance-based profanity checking

  • Switch between checking all words, racist terms, sexual words, or some mixture

  • Custom substitutions

  • Boolean-based profanity checking

SYNOPSIS:

Group.rb:

validates_not_profane :name
validates_not_profane :permalink, :label => "URL"
validates_not_profane :description, :racist => false, :sexual => true

Controller:

Group.create(:name => "Shitty Kids", 
             :permalink => "shitty", 
             :description => "i'm a dumb mick")

produces these errors:

  • Name must not contain any vulgar words

  • URL must not contain any vulgar words

The description, despite having a racial slur for Irish people in it, will pass validation. It's as simple as that!

REQUIREMENTS:

profanalyzer gem - provides the blacklisting backend

INSTALL:

sudo gem install profanalyzer script/plugin install validates_not_profane

OR, if that doesn't work, do

script/plugin install git://github.com/michaeledgar/validates_not_profane.git

LICENSE:

(The MIT License)

Copyright © 2009 Michael J. Edgar

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.