despamilator_rails¶ ↑
DESCRIPTION:¶ ↑
Spam detection plugin for Rails & ActiveRecord. Uses all the standard Rails conventions and my Despamilator gem. This gem only supports Rails 3. See despamilator_rails2 for Rails 2 support.
FEATURES/PROBLEMS:¶ ↑
-
To fix the iconv error when developing with Ruby 1.9.2 and RVM, see: blog.footle.org/2010/07/29/installing-ruby-1-9-2-via-rvm-on-os-x/ .
-
Does not support Rails 2. See despamilator_rails2 for support.
SYNOPSIS:¶ ↑
Somewhere (such as your environment.rb…)
require 'despamilator_rails'
In your model (basic example):
class YourModel < ActiveRecord::Base validate_with_despamilator :attributes => [:some_field] end
When “some_field” is assigned a spammy value, it will add to the errors. For example…
YourModel.new(:some_field => spammy_value).save! #=> ActiveRecord::RecordInvalid exception!
Or…
your_instance = YourModel.new(:some_field => spammy_value) your_instance.save your_instance.errors.full_messages.should #=> ["Some field looks like spam"]
If you want to configure the threshold (which defaults to 1) or add your own callback, you can do the following:
class YourModel < ActiveRecord::Base validate_with_despamilator :attributes => [:some_field], :threshold => 1 do |field, value, despamilator| raise "spam! field: #{field}, value: #{value}, score: #{despamailtor.score}" end end
This example will…
your_instance = YourModel.new(:some_field => "spammy string") your_instance.save! #=> Exception "spam! field: some_field, value: spammy string, score: 123"
The callback will receive the field name, the value and the instance of the Despamilator class.
See the various examples in “spec/fixtures”.
REQUIREMENTS:¶ ↑
-
ActiveRecord >= 2.3.2
-
Despamilator >= 1.0
INSTALL:¶ ↑
-
gem install despamilator_rails
LICENSE:¶ ↑
(The MIT License)
Copyright © 2011 Stephen Hardisty
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.