saintly 0.1.1
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.
- data/History.txt +3 -0
- data/Manifest.txt +7 -0
- data/README.txt +59 -0
- data/Rakefile +24 -0
- data/lib/saintly.rb +55 -0
- data/rails/init.rb +2 -0
- data/test/saintly_test.rb +81 -0
- metadata +124 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
= Saintly
|
2
|
+
|
3
|
+
* http://www.bitbucket.org/digger250/saintly
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A library for censoring naughty words
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* exclude partial matches
|
12
|
+
* exclude whole words
|
13
|
+
* list of allowed words
|
14
|
+
|
15
|
+
== SYNOPSIS:
|
16
|
+
|
17
|
+
Saintly.sanitize(dirty_text)
|
18
|
+
=> "cleaned text"
|
19
|
+
|
20
|
+
In an ActiveRecord model:
|
21
|
+
sanctify :column1, :column2 ...
|
22
|
+
|
23
|
+
You can add words or partials in your config/initializers like so:
|
24
|
+
|
25
|
+
Saintly::RESTRICTED_PARTIALS << 'idiot'
|
26
|
+
Saintly::ALLOWED_WORDS << 'dumbass'
|
27
|
+
Saintly::RESTRICTED_WORDS << 'pansy'
|
28
|
+
|
29
|
+
|
30
|
+
== REQUIREMENTS:
|
31
|
+
|
32
|
+
== INSTALL:
|
33
|
+
|
34
|
+
* gem install saintly
|
35
|
+
|
36
|
+
== LICENSE:
|
37
|
+
|
38
|
+
(The MIT License)
|
39
|
+
|
40
|
+
Copyright (c) 2010 Justin Coyne
|
41
|
+
|
42
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
43
|
+
a copy of this software and associated documentation files (the
|
44
|
+
'Software'), to deal in the Software without restriction, including
|
45
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
46
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
47
|
+
permit persons to whom the Software is furnished to do so, subject to
|
48
|
+
the following conditions:
|
49
|
+
|
50
|
+
The above copyright notice and this permission notice shall be
|
51
|
+
included in all copies or substantial portions of the Software.
|
52
|
+
|
53
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
54
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
55
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
56
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
57
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
58
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
59
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'rake/clean'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'hoe'
|
7
|
+
require 'ruby-debug'
|
8
|
+
CLEAN.include %w(**/*.orig)
|
9
|
+
Hoe.plugins.delete :rubyforge
|
10
|
+
Hoe.plugin :hg
|
11
|
+
|
12
|
+
Hoe.spec 'saintly' do
|
13
|
+
developer('Justin Coyne', 'jcoyne@justincoyne.com')
|
14
|
+
extra_dev_deps << %w(shoulda >=2.10.0) << %w(mocha >=0.9.8)
|
15
|
+
end
|
16
|
+
|
17
|
+
task :install =>:package do
|
18
|
+
$:<< 'lib'
|
19
|
+
require 'saintly'
|
20
|
+
debugger
|
21
|
+
puts `GEM_HOME=~/.gem/ruby/1.8 gem install pkg/saintly-#{Saintly::VERSION}.gem`
|
22
|
+
end
|
23
|
+
# vim: syntax=ruby
|
24
|
+
#
|
data/lib/saintly.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Saintly
|
2
|
+
VERSION = "0.1.1"
|
3
|
+
|
4
|
+
def self.sanitize(text)
|
5
|
+
text.gsub(exclude_regex){|m| ALLOWED_WORDS.include?(m) ? m : '*' * m.length}
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def self.exclude_regex
|
11
|
+
/\b(#{(RESTRICTED_WORDS + partials_regex_array).join('|')})\b/
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.partials_regex_array
|
15
|
+
RESTRICTED_PARTIALS.map{|w| '\w*' + w + '\w*'}
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
ALLOWED_WORDS = [ 'glass', 'scunthorpe', 'assume', 'assumption', 'assassin', 'assassinate', 'shitake']
|
20
|
+
|
21
|
+
|
22
|
+
RESTRICTED_PARTIALS = [
|
23
|
+
'fuck',
|
24
|
+
'shit',
|
25
|
+
'ass',
|
26
|
+
'nigger',
|
27
|
+
'cunt'
|
28
|
+
]
|
29
|
+
|
30
|
+
RESTRICTED_WORDS = [
|
31
|
+
'twat'
|
32
|
+
]
|
33
|
+
|
34
|
+
module Rails
|
35
|
+
|
36
|
+
def self.included(base)
|
37
|
+
base.extend ClassMethods
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
module ClassMethods
|
42
|
+
def sanctify(*args)
|
43
|
+
options = args.last.instance_of?(Hash) ? args.pop : {}
|
44
|
+
define_attribute_methods
|
45
|
+
|
46
|
+
args.each do |col|
|
47
|
+
define_method (col.to_s+"_with_saintly").to_sym do
|
48
|
+
Saintly.sanitize(read_attribute(col))
|
49
|
+
end
|
50
|
+
alias_method_chain col, :saintly
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require "test/unit"
|
3
|
+
require 'saintly'
|
4
|
+
require 'shoulda'
|
5
|
+
require 'mocha'
|
6
|
+
require 'ruby-debug'
|
7
|
+
|
8
|
+
class SaintlyTest < Test::Unit::TestCase
|
9
|
+
should "sanitize full word" do
|
10
|
+
assert_equal '****', Saintly.sanitize('fuck')
|
11
|
+
assert_equal '***', Saintly.sanitize('ass')
|
12
|
+
assert_equal '****', Saintly.sanitize('shit')
|
13
|
+
assert_equal '****', Saintly.sanitize('cunt')
|
14
|
+
assert_equal '****', Saintly.sanitize('twat')
|
15
|
+
assert_equal '******', Saintly.sanitize('nigger')
|
16
|
+
|
17
|
+
end
|
18
|
+
should "sanitize partial words" do
|
19
|
+
assert_equal '*******', Saintly.sanitize('fucking')
|
20
|
+
assert_equal '*******', Saintly.sanitize('asshole')
|
21
|
+
assert_equal '********', Saintly.sanitize('shithead')
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
should "not sanitize allowed words" do
|
26
|
+
assert_equal 'shitake', Saintly.sanitize('shitake')
|
27
|
+
|
28
|
+
assert_equal 'assassin', Saintly.sanitize('assassin')
|
29
|
+
assert_equal 'assumption', Saintly.sanitize('assumption')
|
30
|
+
assert_equal 'assume', Saintly.sanitize('assume')
|
31
|
+
assert_equal 'glass', Saintly.sanitize('glass')
|
32
|
+
|
33
|
+
assert_equal 'scunthorpe', Saintly.sanitize('scunthorpe')
|
34
|
+
assert_equal 'lightwater', Saintly.sanitize('lightwater')
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
class MockArModel
|
39
|
+
|
40
|
+
def self.define_attribute_methods
|
41
|
+
end
|
42
|
+
def self.alias_method_chain(method, behavior)
|
43
|
+
alias_method (method.to_s + '_without_' + behavior.to_s).to_sym, method
|
44
|
+
alias_method method, (method.to_s + '_with_' + behavior.to_s).to_sym
|
45
|
+
|
46
|
+
end
|
47
|
+
def body
|
48
|
+
read_attribute(:body)
|
49
|
+
end
|
50
|
+
|
51
|
+
def title
|
52
|
+
read_attribute(:title)
|
53
|
+
end
|
54
|
+
|
55
|
+
def read_attribute (col)
|
56
|
+
case col
|
57
|
+
when :body
|
58
|
+
'assassin ass fucking'
|
59
|
+
when :title
|
60
|
+
'typical shithead'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
include Saintly::Rails
|
65
|
+
sanctify :body, :title
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
context "rails app" do
|
71
|
+
setup do
|
72
|
+
@m = MockArModel.new
|
73
|
+
end
|
74
|
+
|
75
|
+
should "create new methods" do
|
76
|
+
assert_equal 'assassin ass fucking', @m.body_without_saintly
|
77
|
+
assert_equal 'assassin *** *******', @m.body
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: saintly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Justin Coyne
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-30 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 39
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 10
|
33
|
+
- 0
|
34
|
+
version: 2.10.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: mocha
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 43
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 9
|
49
|
+
- 8
|
50
|
+
version: 0.9.8
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: hoe
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 21
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 6
|
65
|
+
- 1
|
66
|
+
version: 2.6.1
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
69
|
+
description: A library for censoring naughty words
|
70
|
+
email:
|
71
|
+
- jcoyne@justincoyne.com
|
72
|
+
executables: []
|
73
|
+
|
74
|
+
extensions: []
|
75
|
+
|
76
|
+
extra_rdoc_files:
|
77
|
+
- History.txt
|
78
|
+
- Manifest.txt
|
79
|
+
- README.txt
|
80
|
+
files:
|
81
|
+
- History.txt
|
82
|
+
- Manifest.txt
|
83
|
+
- README.txt
|
84
|
+
- Rakefile
|
85
|
+
- lib/saintly.rb
|
86
|
+
- rails/init.rb
|
87
|
+
- test/saintly_test.rb
|
88
|
+
has_rdoc: true
|
89
|
+
homepage: http://www.bitbucket.org/digger250/saintly
|
90
|
+
licenses: []
|
91
|
+
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options:
|
94
|
+
- --main
|
95
|
+
- README.txt
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
requirements: []
|
117
|
+
|
118
|
+
rubyforge_project: saintly
|
119
|
+
rubygems_version: 1.3.7
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: A library for censoring naughty words
|
123
|
+
test_files: []
|
124
|
+
|