Module: Defender

Defined in:
lib/defender.rb,
lib/defender/version.rb,
lib/defender/spammable.rb,
lib/defender/defender_error.rb

Overview

Public: The main Defender module. This is the namespace under which all of Defender is.

Defined Under Namespace

Modules: Spammable, Test Classes: DefenderError

Constant Summary collapse

VERSION =

Current Defender version

'2.0.3'

Class Method Summary collapse

Class Method Details

.api_keyObject

Public: Returns the Defensio API key String set with #api_key=



19
20
21
# File 'lib/defender.rb', line 19

def self.api_key
  @api_key
end

.api_key=(api_key) ⇒ Object

Public: Set the Defensio API key. Get one at defensio.com.

Defender will not work without a Defensio API key.

Returns the Defensio API key string.



14
15
16
# File 'lib/defender.rb', line 14

def self.api_key=(api_key)
  @api_key = api_key.to_s
end

.defensioObject

Internal: The Defensio backend. If no backend has been set yet, this will create one with the API key set with #api_key=.

Returns the Defensio backend.



52
53
54
55
56
# File 'lib/defender.rb', line 52

def self.defensio
  return @defensio  if defined?(@defensio)
  require 'defensio'
  @defensio ||= Defensio.new(@api_key, "Defender | #{VERSION} | Henrik Hodne | [email protected]")
end

.defensio=(defensio) ⇒ Object

Internal: This is for replacing the Defensio backend when running tests.



44
45
46
# File 'lib/defender.rb', line 44

def self.defensio=(defensio)
  @defensio = defensio
end

.test_modeObject

Public: Returns whether Defender is in “test mode”.

When in test mode, you can specify what kind of response you want in the content field. If you want a comment to be marked as spam with a spaminess of 0.85, you write [spam,0.85] somewhere in the content field of the document. If you want a malicious response with a spaminess of 0.99 you write [malicious,0.99], and for an innocent response you write [innocent,0.25]. This is the preferred way of testing, and if you test by writing “spammy” comments, you might hurt the Defensio performance.



32
33
34
# File 'lib/defender.rb', line 32

def self.test_mode
  !!@test_mode
end

.test_mode=(test_mode) ⇒ Object

Public: Enables/disables Defender’s test mode. You can use this, or the configure_defender method to enable the test mode, but you should probably use this if you only temporarily want to enable the test mode.



39
40
41
# File 'lib/defender.rb', line 39

def self.test_mode=(test_mode)
  @test_mode = test_mode
end