cleanerupper 0.1.0 → 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.
@@ -0,0 +1,105 @@
1
+ # Cleanerupper #
2
+
3
+ Cleanerupper can be used in any ActiveRecord based model to seamless clean, sanitize, and
4
+ remove inappropriate or sensitive data.
5
+
6
+ # Using Cleanerupper #
7
+
8
+ Cleanerupper relies on a dictionary file located in the config directory of your rails
9
+ application called `dictionary.yml`. This file is structured as so:
10
+
11
+ words:
12
+ these
13
+ words
14
+ will
15
+ be
16
+ cleaned
17
+
18
+ A default dictionary is included with this project, but only contains some test data for you to get started. These words can be accessed via the `Cleaner::Dictionary` object, which has several dictionaries:
19
+
20
+ Cleaner::Dictionary.words => Array of words from the dictionary
21
+ Cleaner::Dictionary.replacement_chars => Array of characters to use for the `replace` method
22
+ Cleaner::Dictionary.file => Filepath of the used dictionary file
23
+ Cleaner::Dictionary.cleaner_methods => List of cleaner methods included in this release
24
+
25
+ It works by providing a new method to all of your ActiveRecord based objects called `clean`
26
+
27
+ class Widget < ActiveRecord::Base
28
+ clean :body, :with => :scramble
29
+ end
30
+
31
+ This method takes an array of columns to be cleaned by cleanerupper, followed by two options:
32
+
33
+ :with => specifies which method to clean with
34
+ :callback => specifies a callback to call if disallowed data is found
35
+
36
+ Three method have been provided for cleaning convenience, which are:
37
+
38
+ :scramble => keeps all characters, but scrambles the word
39
+ :remove => removes the word completely
40
+ :replace => replaces all characters of the word with $%@^ text
41
+
42
+ If no method is defined, `:scramble` will be used. You can also define your own function, like so:
43
+
44
+ class Widget < ActiveRecord::Base
45
+ clean :body, :with => :custom
46
+
47
+ def custom(found)
48
+ Cleaner::Dictionary.words.each do |word|
49
+ found.gsub!(word, "CUSTOM") if found.include?(word)
50
+ end
51
+ return found
52
+ end
53
+ end
54
+
55
+ In the example above, we make use of the word dictionary to check our column for bad words.
56
+
57
+ You can also define a callback. This callback will only be called if bad data was found in any of
58
+ the columns. If the callback returns falls, the save will fail (this works the same way as a `before_save`).
59
+
60
+ class Widget < ActiveRecord::Base
61
+ clean :body, :with => :scramble, :callback => :found_words
62
+
63
+ def found_words
64
+ Emailer.email_teacher("Your student used a bad word!")
65
+ true
66
+ end
67
+ end
68
+
69
+
70
+ Examples
71
+ =======
72
+
73
+ # Clean different columns with different methods
74
+ class Widget < ActiveRecord::Base
75
+ clean :body, :title, :with => :replace
76
+ clean :author_name, :with => :scramble
77
+ end
78
+
79
+ # Clean the body, and send an email if this is the first time a bad word has been used
80
+ class Widget < ActiveRecord::Base
81
+ clean :body, :with => :replace, :callback => :send_email
82
+
83
+ def send_email
84
+ if self.author.infractions >= 1
85
+ Mailer.send_infraction(self.author)
86
+ return true
87
+ end
88
+ return false #Don't save this if they've already been notified about the rules!
89
+ end
90
+ end
91
+
92
+ # Custom cleaning method
93
+ class Widget < ActiveRecord::Base
94
+ clean :body, :title, :author_name, :with => :remove_vowels
95
+
96
+ def remove_vowels(found)
97
+ Cleaner::Dictionary.words.each do |word|
98
+ found.gsub!(/#{word}/, word.gsub(/(a|e|i|o|u)/, "")
99
+ end
100
+ return found
101
+ end
102
+ end
103
+
104
+ # Copyright and Licensing #
105
+ Copyright (c) 2010 Mike Trpcic (Fluid Media Inc.), released under the MIT license
@@ -5,23 +5,25 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cleanerupper}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mike Trpcic"]
12
- s.date = %q{2010-04-09}
12
+ s.date = %q{2010-04-10}
13
13
  s.email = %q{mike@fluidmedia.com}
14
14
  s.extra_rdoc_files = [
15
- "README"
15
+ "README.markdown"
16
16
  ]
17
17
  s.files = [
18
- "./cleanerupper-0.1.0.gem",
18
+ "./README.markdown",
19
19
  "./cleanerupper.gemspec",
20
+ "./cleanerupper.sqlite3.db",
20
21
  "./dictionary.yml",
21
22
  "./init.rb",
22
23
  "./install.rb",
23
24
  "./lib/cleanerupper.rb",
24
25
  "./pkg/cleanerupper-0.0.0.gem",
26
+ "./pkg/cleanerupper-0.1.0.gem",
25
27
  "./rails/init.rb",
26
28
  "./tasks/cleanerupper_tasks.rake",
27
29
  "./test/cleanerupper_test.rb",
@@ -34,8 +36,13 @@ Gem::Specification.new do |s|
34
36
  s.homepage = %q{http://github.com/fmiopensource/cleanerupper}
35
37
  s.rdoc_options = ["--charset=UTF-8"]
36
38
  s.require_paths = ["lib"]
37
- s.rubygems_version = %q{1.3.5}
39
+ s.rubygems_version = %q{1.3.6}
38
40
  s.summary = %q{Simple database sanitation}
41
+ s.test_files = [
42
+ "test/schema.rb",
43
+ "test/cleanerupper_test.rb",
44
+ "test/test_helper.rb"
45
+ ]
39
46
 
40
47
  if s.respond_to? :specification_version then
41
48
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
Binary file
@@ -1,3 +1,6 @@
1
1
  words:
2
- default
3
- dictionary
2
+ foo
3
+ bar
4
+ baz
5
+ test
6
+ hippopotamus
@@ -53,8 +53,7 @@ module Cleaner
53
53
  new_value = self.send(method, old_value.dup)
54
54
  end
55
55
  unless new_value == old_value
56
- #debugger
57
- to_save = callback.nil? ? true : self.send(callback)
56
+ to_save = callback.nil? ? true : self.send(callback) == false ? false : true
58
57
  write_attribute(column, new_value) if to_save
59
58
  end
60
59
  end
@@ -2339,3 +2339,51 @@
2339
2339
  CustomWidget Load (0.3ms) SELECT * FROM "custom_widgets" WHERE ("custom_widgets"."id" = 1) 
2340
2340
  ScrambleWidget Create (0.2ms) INSERT INTO "scramble_widgets" ("title", "body", "author_name") VALUES('cleanerupper eetda_stuftl body', NULL, NULL)
2341
2341
  ScrambleWidget Load (0.2ms) SELECT * FROM "scramble_widgets" WHERE ("scramble_widgets"."id" = 2) 
2342
+ SQL (0.4ms) select sqlite_version(*)
2343
+ SQL (0.2ms)  SELECT name
2344
+ FROM sqlite_master
2345
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2346
+ 
2347
+ SQL (29.3ms) CREATE TABLE "widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(100), "body" varchar(255), "author_name" varchar(100)) 
2348
+ SQL (0.2ms)  SELECT name
2349
+ FROM sqlite_master
2350
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2351
+ 
2352
+ SQL (3.8ms) CREATE TABLE "replace_widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(100), "body" varchar(255), "author_name" varchar(100)) 
2353
+ SQL (0.2ms)  SELECT name
2354
+ FROM sqlite_master
2355
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2356
+ 
2357
+ SQL (91.3ms) CREATE TABLE "remove_widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(100), "body" varchar(255), "author_name" varchar(100)) 
2358
+ SQL (0.2ms)  SELECT name
2359
+ FROM sqlite_master
2360
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2361
+ 
2362
+ SQL (19.9ms) CREATE TABLE "scramble_widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(100), "body" varchar(255), "author_name" varchar(100)) 
2363
+ SQL (0.3ms)  SELECT name
2364
+ FROM sqlite_master
2365
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2366
+ 
2367
+ SQL (3.8ms) CREATE TABLE "custom_widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(100), "body" varchar(255), "author_name" varchar(100)) 
2368
+ SQL (0.2ms)  SELECT name
2369
+ FROM sqlite_master
2370
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2371
+ 
2372
+ SQL (260.9ms) CREATE TABLE "callback_widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(100), "body" varchar(255), "author_name" varchar(100)) 
2373
+ SQL (0.3ms)  SELECT name
2374
+ FROM sqlite_master
2375
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2376
+ 
2377
+ SQL (5.2ms) CREATE TABLE "false_callback_widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(100), "body" varchar(255), "author_name" varchar(100)) 
2378
+ SQL (0.2ms)  SELECT name
2379
+ FROM sqlite_master
2380
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2381
+ 
2382
+ SQL (3.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
2383
+ SQL (25.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
2384
+ SQL (0.3ms)  SELECT name
2385
+ FROM sqlite_master
2386
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2387
+ 
2388
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
2389
+ SQL (3.5ms) INSERT INTO "schema_migrations" (version) VALUES ('1')
@@ -3,7 +3,7 @@ require 'active_support'
3
3
  require 'active_support/test_case'
4
4
 
5
5
  if ENV['RAILS'].nil?
6
- require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))
6
+ require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))
7
7
  else
8
8
  # specific rails version targeted
9
9
  # load activerecord and plugin manually
@@ -27,4 +27,4 @@ load(File.dirname(__FILE__) + "/schema.rb")
27
27
  require File.expand_path(File.dirname(__FILE__) + "/../lib/cleanerupper.rb")
28
28
  ENV["RAILS_ENV"] = "test"
29
29
  require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
30
- require 'test_help'
30
+ require 'test_help'
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cleanerupper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - Mike Trpcic
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-04-09 00:00:00 -04:00
17
+ date: 2010-04-10 00:00:00 -04:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -20,15 +25,17 @@ executables: []
20
25
  extensions: []
21
26
 
22
27
  extra_rdoc_files:
23
- - README
28
+ - README.markdown
24
29
  files:
25
- - ./cleanerupper-0.1.0.gem
30
+ - ./README.markdown
26
31
  - ./cleanerupper.gemspec
32
+ - ./cleanerupper.sqlite3.db
27
33
  - ./dictionary.yml
28
34
  - ./init.rb
29
35
  - ./install.rb
30
36
  - ./lib/cleanerupper.rb
31
37
  - ./pkg/cleanerupper-0.0.0.gem
38
+ - ./pkg/cleanerupper-0.1.0.gem
32
39
  - ./rails/init.rb
33
40
  - ./tasks/cleanerupper_tasks.rake
34
41
  - ./test/cleanerupper_test.rb
@@ -37,7 +44,7 @@ files:
37
44
  - ./test/schema.rb
38
45
  - ./test/test_helper.rb
39
46
  - ./uninstall.rb
40
- - README
47
+ - README.markdown
41
48
  has_rdoc: true
42
49
  homepage: http://github.com/fmiopensource/cleanerupper
43
50
  licenses: []
@@ -51,20 +58,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
58
  requirements:
52
59
  - - ">="
53
60
  - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
54
63
  version: "0"
55
- version:
56
64
  required_rubygems_version: !ruby/object:Gem::Requirement
57
65
  requirements:
58
66
  - - ">="
59
67
  - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
60
70
  version: "0"
61
- version:
62
71
  requirements: []
63
72
 
64
73
  rubyforge_project:
65
- rubygems_version: 1.3.5
74
+ rubygems_version: 1.3.6
66
75
  signing_key:
67
76
  specification_version: 3
68
77
  summary: Simple database sanitation
69
- test_files: []
70
-
78
+ test_files:
79
+ - test/schema.rb
80
+ - test/cleanerupper_test.rb
81
+ - test/test_helper.rb
data/README DELETED
@@ -1,40 +0,0 @@
1
- Cleanerupper
2
- ============
3
-
4
- Cleanerupper can be used in any ActiveRecord based model to seamless clean, sanitize, and
5
- remove inappropriate or sensitive data.
6
-
7
-
8
- Examples
9
- =======
10
-
11
- class Widget < ActiveRecord::Base
12
- #The primary use of CleanerUpper is to be used as
13
- #before_save filters.
14
-
15
- #This will scramble the data before it is saved:
16
- scramble :body, :title
17
-
18
- #This will remove the data before it is saved:
19
- remove :body, :title
20
-
21
- #This will replace the data before it is saved:
22
- replace :body, :title
23
-
24
- #You can also define a block if you are using multiple
25
- #different cleaning methods:
26
- cleaner do |c|
27
- c.scramble :body
28
- c.remove :title
29
- c.replace :author_name
30
- end
31
- end
32
-
33
- #You can also manually invoke the cleaning methods on an
34
- #instance of any ActiveRecord object like so:
35
- w = Widget.last
36
- w.clean(:body)
37
- w.scramble(:title)
38
- w.remove(:author_name)
39
-
40
- Copyright (c) 2010 Mike Trpcic (Fluid Media Inc.), released under the MIT license
File without changes