Module: Defender::Spammable

Included in:
Test::Comment
Defined in:
lib/defender/spammable.rb

Overview

Includes all the model magic for Defender. This module should be included in your model to enable Defender on it. Defender does some automatic detection on your setup, but you need to do some configuration yourself. You can set the API key in two different ways. If you only use Defender on one model, you can configure the API key in the model with the configure_defender method. If you prefer to use initializers, or you have multiple models, you probably want to define it in an initializer. You can do this by calling Defender.api_key directly, like this:

Defender.api_key = 'This is your API key'

Defender only requires your models to have a before_save callback, but since most ActiveModel libraries should have this you only need to worry about it if you’re making your own models. Just have a look at Defender::Test::Comment for an example comment model.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Constant Summary collapse

DEFENSIO_KEYS =

Public: These are the default attribute names Defender will pull information from if no other names are configured. So the content of the comment will be pulled from ‘body’, if that attribute exists. Otherwise, it will be pulled from ‘content’. If that doesn’t exist either, it will pull from ‘comment’. If that attribute doesn’t exist either, you should configure your own attributes with the configure_defender method.

{
  'content' => [:body, :content, :comment],
  'author-name' => [:author_name, :author],
  'author-email' => [:author_email, :email],
  'author-ip' => [:author_ip, :ip],
  'author-url' => [:author_url, :url]
}.freeze

Class Method Summary collapse

Class Method Details

.included(receiver) ⇒ Object

Internal: Includes the ClassMethods and InstanceMethods and sets up the before_save callback.



232
233
234
235
236
# File 'lib/defender/spammable.rb', line 232

def self.included(receiver)
  receiver.extend         ClassMethods
  receiver.send :include, InstanceMethods
  receiver.send :before_create, :_defender_before_create
end