Module Defensio::ActsAs::ClassMethods
In: lib/defensio/acts_as.rb

Methods

Included Modules

InstanceMethods

Public Instance methods

Add Defensio magic to an ActiveRecord class.

Options are the same as +Defensio::Client#new+ plus the :fields option that allows to customize the fields that will be sent to Defensio to help the classification of a comment. For example if the content of a comment is stored in the comment column set the :fields option to { :content => :comment }. Try to map as much column as possible as this helps Defensio to classify one comment effectively.

You can also set the type of comment with the :comment_type option.

Usage: <tt>

  acts_as_defensio_comment :owner_url => 'http://code.macournoyer.com/svn/plugins/defensio',
                           :fields => { :content => :comment }

</tt>

You must specify the :api_key and :owner_url option. Other options are optional. All options can be specified in a YAML config file by default in RAILS_ROOT/config/defensio.yml.

[Source]

    # File lib/defensio/acts_as.rb, line 60
60:       def acts_as_defensio(type, options={})
61:         include InstanceMethods
62:         
63:         case type
64:         when :article
65:           if options.has_key? :announce_when
66:             after_save :announce_article
67:           else
68:             after_create :announce_article!
69:           end
70:         when :comment
71:           after_create :audit_comment
72:         end
73:         
74:         @defensio_type = type
75:         self.defensio_options = options
76:         @defensio = Defensio::Client.new(@defensio_options)
77:         
78:         raise Defensio::InvalidAPIKey unless @defensio.validate_key.success?        
79:       end

Add Defensio magic for managing an article or something that can be commented (spamed) about. By default those following fields are maped to the column of the same name, if the column exists: <tt>

  author, author_email, title, content, permalink

</tt> By default the article will be published after creation. You can override this behaviour with the :announce_when option. Specified a method returning if the article needs to be announced to the Defensio server. If you‘re using the :announce_when option, you‘ll also need to create an announced column as this will be set to true when the article is published. See acts_as_defensio for more details.

[Source]

    # File lib/defensio/acts_as.rb, line 34
34:       def acts_as_defensio_article(options={})
35:         acts_as_defensio :article, options
36:       end

Add Defensio magic for managing a comment or something that can be marked as Spam or Ham. By default those following fields are maped to the column of the same name, if the column exists: <tt>

  author, content, title, author_email, author_url,
  user_logged_in, trusted_user, article.permalink

</tt> See acts_as_defensio for more details.

[Source]

    # File lib/defensio/acts_as.rb, line 16
16:       def acts_as_defensio_comment(options={})
17:         acts_as_defensio :comment, options
18:       end

[Source]

     # File lib/defensio/acts_as.rb, line 104
104:       def comment_type
105:         @defensio_options[:comment_type] || 'comment'
106:       end

[Source]

    # File lib/defensio/acts_as.rb, line 81
81:       def defensio
82:         @defensio
83:       end

[Source]

     # File lib/defensio/acts_as.rb, line 100
100:       def defensio_fields(field)
101:         (@defensio_options[:fields] || {})[field] || field
102:       end

[Source]

    # File lib/defensio/acts_as.rb, line 92
92:       def defensio_options
93:         @defensio_options
94:       end

[Source]

    # File lib/defensio/acts_as.rb, line 85
85:       def defensio_options=(options)
86:         @defensio_options = {}
87:         @defensio_options.merge! File.open(Defensio.config_file) { |file| YAML.load(file) }[ENV['RAILS_ENV']] if File.exists?(Defensio.config_file)
88:         @defensio_options.merge! options
89:         @defensio_options.symbolize_keys!
90:       end

[Source]

     # File lib/defensio/acts_as.rb, line 108
108:       def defensio_stats
109:         @defensio.get_stats
110:       end

[Source]

    # File lib/defensio/acts_as.rb, line 96
96:       def defensio_type
97:         @defensio_type
98:       end

[Validate]