filters_spam 0.3 → 0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/filters_spam.rb +12 -12
- data/readme.md +25 -16
- metadata +23 -43
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f0df64a0b5c2e0e4c04f8b22f9974791b9710154
|
4
|
+
data.tar.gz: b6de56c62d62a340eec4cec4df8b180f2b74cd61
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fae7eca9e41ed5925beab0b013f3bb9ce88cb01e9cb26cf5ff69af84dfa778ed2746a894815fa465b6961dc0aefbd6520b9c7935bc8a5bd14aea2116df19bd17
|
7
|
+
data.tar.gz: 6bb7e68cd97280415e51d950873467287a09d13ec2fd4cecb2d971a6c60dd7ed9693a37275479ac40f4b4bf4af16e75a8568846241ae96582012371639d5ae0d
|
data/lib/filters_spam.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Just call filters_spam in your model with any of the options you want.
|
2
2
|
def filters_spam(options = {})
|
3
3
|
options = {
|
4
|
-
:message_field => :
|
4
|
+
:message_field => :nil,
|
5
5
|
:email_field => :email,
|
6
6
|
:author_field => :author,
|
7
7
|
:other_fields => [],
|
@@ -13,8 +13,8 @@ def filters_spam(options = {})
|
|
13
13
|
named_scope :ham, :conditions => {:spam => false}
|
14
14
|
named_scope :spam, :conditions => {:spam => true}
|
15
15
|
else
|
16
|
-
scope :ham,
|
17
|
-
scope :spam,
|
16
|
+
scope :ham, lambda { where(:spam => false) }
|
17
|
+
scope :spam, lambda { where(:spam => true) }
|
18
18
|
end
|
19
19
|
before_validation(:on => :create) { |spammable| spammable.send(:calculate_spam_score) }
|
20
20
|
|
@@ -61,7 +61,7 @@ def filters_spam(options = {})
|
|
61
61
|
def score_for_previous_submissions
|
62
62
|
current_score = 0
|
63
63
|
|
64
|
-
self.class.
|
64
|
+
self.class.where(:#{options[:email_field]} => #{options[:email_field]}).each do |i|
|
65
65
|
if i.spam?
|
66
66
|
current_score -= 1
|
67
67
|
else
|
@@ -78,7 +78,7 @@ def filters_spam(options = {})
|
|
78
78
|
spam_words.each do |word|
|
79
79
|
regex = /\#{word}/i
|
80
80
|
if #{options[:message_field]} =~ regex ||
|
81
|
-
#{options[:author_field]} =~ regex #{" || #{options[:other_fields].join(' =~ regex ')} =~ regex" if options[:other_fields].any?}
|
81
|
+
#{options[:author_field]} =~ regex #{" || #{options[:other_fields].join(' =~ regex || ')} =~ regex" if options[:other_fields].any?}
|
82
82
|
current_score -= 1
|
83
83
|
end
|
84
84
|
end
|
@@ -107,7 +107,7 @@ def filters_spam(options = {})
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def score_for_same_message
|
110
|
-
self.class.
|
110
|
+
self.class.where(:#{options[:message_field]} => #{options[:message_field]}).count * -1
|
111
111
|
end
|
112
112
|
|
113
113
|
def score_for_consonant_runs
|
@@ -124,14 +124,14 @@ def filters_spam(options = {})
|
|
124
124
|
|
125
125
|
def calculate_spam_score
|
126
126
|
score = 0
|
127
|
-
score += score_for_message_links
|
128
|
-
score += score_for_message_length
|
127
|
+
score += score_for_message_links if #{options[:message_field]}
|
128
|
+
score += score_for_message_length if #{options[:message_field]}
|
129
129
|
score += score_for_previous_submissions
|
130
130
|
score += score_for_spam_words
|
131
|
-
score += score_for_suspect_tld
|
132
|
-
score += score_for_lame_message_start
|
131
|
+
score += score_for_suspect_tld if #{options[:message_field]}
|
132
|
+
score += score_for_lame_message_start if #{options[:message_field]}
|
133
133
|
score += score_for_author_link
|
134
|
-
score += score_for_same_message
|
134
|
+
score += score_for_same_message if #{options[:message_field]}
|
135
135
|
score += score_for_consonant_runs
|
136
136
|
self.spam = (score < 0)
|
137
137
|
|
@@ -140,4 +140,4 @@ def filters_spam(options = {})
|
|
140
140
|
true
|
141
141
|
end
|
142
142
|
}
|
143
|
-
end
|
143
|
+
end
|
data/readme.md
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
# FiltersSpam
|
2
2
|
|
3
|
-
This is a small Ruby on Rails plugin that can be installed as a gem in your
|
3
|
+
This is a small Ruby on Rails plugin that can be installed as a gem in your `Gemfile`
|
4
4
|
that allows models to attach to it to provide spam filtering functionality.
|
5
5
|
|
6
6
|
## Rails Quickstart
|
7
7
|
|
8
|
-
|
9
|
-
gem 'filters_spam', '~> 0.3'
|
8
|
+
Add to your Gemfile:
|
10
9
|
|
11
|
-
|
10
|
+
```ruby
|
11
|
+
gem 'filters_spam', '~> 0.4'
|
12
|
+
```
|
13
|
+
|
14
|
+
Run `bundle install`.
|
12
15
|
|
13
16
|
## Usage
|
14
17
|
|
@@ -25,31 +28,37 @@ The same thing in Rails 3:
|
|
25
28
|
|
26
29
|
Now, you can use it by calling the function in your model like so:
|
27
30
|
|
28
|
-
|
31
|
+
```ruby
|
32
|
+
filters_spam
|
33
|
+
```
|
29
34
|
|
30
35
|
If you want to change the default fields that are used by ``filters_spam``
|
31
36
|
then you can pass them in to the method as options. All options are optional.
|
32
37
|
|
33
38
|
All of the possible options are outlined below with the default values for each:
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
```ruby
|
41
|
+
filters_spam({
|
42
|
+
:message_field => :message,
|
43
|
+
:email_field => :email,
|
44
|
+
:author_field => :author,
|
45
|
+
:other_fields => [],
|
46
|
+
:extra_spam_words => %w()
|
47
|
+
})
|
48
|
+
```
|
42
49
|
|
43
50
|
So, say you wanted to mark 'ruby' and 'rails' as spam words you simply pass them
|
44
51
|
in using the ``:extra_spam_words`` option:
|
45
52
|
|
46
|
-
|
47
|
-
|
48
|
-
|
53
|
+
```ruby
|
54
|
+
filters_spam({
|
55
|
+
:extra_spam_words => %w(ruby rails)
|
56
|
+
})
|
57
|
+
```
|
49
58
|
|
50
59
|
Enjoy a life with less spam.
|
51
60
|
|
52
61
|
## Credits
|
53
62
|
|
54
63
|
This code was inspired by Russel Norris' [acts_as_snook plugin](http://github.com/rsl/acts_as_snook)
|
55
|
-
and ideas presented by [Jonathan Snook](http://snook.ca/archives/other/effective_blog_comment_spam_blocker)
|
64
|
+
and ideas presented by [Jonathan Snook](http://snook.ca/archives/other/effective_blog_comment_spam_blocker)
|
metadata
CHANGED
@@ -1,68 +1,48 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: filters_spam
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
version: "0.3"
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.4'
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Philip Arndt
|
13
8
|
- David Jones
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2010-09-14 00:00:00 +12:00
|
19
|
-
default_executable:
|
12
|
+
date: 2014-04-30 00:00:00.000000000 Z
|
20
13
|
dependencies: []
|
21
|
-
|
22
|
-
|
14
|
+
description: This is a small Ruby on Rails plugin that can be installed as a gem in
|
15
|
+
your Gemfile that allows models to attach to it to provide spam filtering functionality.
|
23
16
|
email: info@resolvedigital.co.nz
|
24
17
|
executables: []
|
25
|
-
|
26
18
|
extensions: []
|
27
|
-
|
28
19
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
31
|
-
- readme.md
|
20
|
+
files:
|
32
21
|
- lib/filters_spam.rb
|
33
|
-
|
22
|
+
- readme.md
|
34
23
|
homepage: http://www.resolvedigital.co.nz
|
35
24
|
licenses: []
|
36
|
-
|
25
|
+
metadata: {}
|
37
26
|
post_install_message:
|
38
27
|
rdoc_options: []
|
39
|
-
|
40
|
-
require_paths:
|
28
|
+
require_paths:
|
41
29
|
- lib
|
42
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
-
|
44
|
-
requirements:
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
45
32
|
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
version: "0"
|
51
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
|
-
requirements:
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
54
37
|
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
|
58
|
-
- 0
|
59
|
-
version: "0"
|
60
|
-
requirements:
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements:
|
61
41
|
- none
|
62
42
|
rubyforge_project:
|
63
|
-
rubygems_version:
|
43
|
+
rubygems_version: 2.2.2
|
64
44
|
signing_key:
|
65
|
-
specification_version:
|
45
|
+
specification_version: 4
|
66
46
|
summary: Attach to your model to have this filter out the spam using scoring techniques.
|
67
47
|
test_files: []
|
68
|
-
|
48
|
+
has_rdoc:
|