cleanerupper 0.2.0 → 0.2.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/cleanerupper.gemspec +3 -2
- data/lib/cleanerupper.rb +4 -4
- data/pkg/cleanerupper-0.2.0.gem +0 -0
- data/test/cleanerupper_test.rb +18 -2
- data/test/debug.log +81 -0
- metadata +4 -3
data/cleanerupper.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cleanerupper}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.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-
|
12
|
+
s.date = %q{2010-04-20}
|
13
13
|
s.email = %q{mike@fluidmedia.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.markdown"
|
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
"./pkg/cleanerupper-0.0.0.gem",
|
25
25
|
"./pkg/cleanerupper-0.1.0.gem",
|
26
26
|
"./pkg/cleanerupper-0.1.1.gem",
|
27
|
+
"./pkg/cleanerupper-0.2.0.gem",
|
27
28
|
"./rails/init.rb",
|
28
29
|
"./tasks/cleanerupper_tasks.rake",
|
29
30
|
"./test/cleanerupper_test.rb",
|
data/lib/cleanerupper.rb
CHANGED
@@ -42,7 +42,7 @@ module Cleaner
|
|
42
42
|
|
43
43
|
#Append the following methods to the ActiveRecord::Base class
|
44
44
|
def bind(column, method, dictionary, callback = nil)
|
45
|
-
|
45
|
+
dictionary = [dictionary].flatten.map{|d| Cleaner::Data.dictionaries[d]}.flatten.uniq
|
46
46
|
old_value = read_attribute(column)
|
47
47
|
to_save = true
|
48
48
|
|
@@ -81,7 +81,7 @@ module Cleaner
|
|
81
81
|
|
82
82
|
#This method scrambles data by rearranging the letters.
|
83
83
|
def scramble(value, dict)
|
84
|
-
|
84
|
+
dict.each do |word|
|
85
85
|
value.to_s.gsub!(/#{word}/, word.split(//).shuffle.join(''))
|
86
86
|
end
|
87
87
|
value
|
@@ -90,7 +90,7 @@ module Cleaner
|
|
90
90
|
#This method removes selected words from the string and replaces them
|
91
91
|
#with nothing
|
92
92
|
def remove(value, dict)
|
93
|
-
|
93
|
+
dict.each do |word|
|
94
94
|
value.to_s.gsub!(/#{word}/, "")
|
95
95
|
end
|
96
96
|
value
|
@@ -99,7 +99,7 @@ module Cleaner
|
|
99
99
|
#This method removes selected words from the string and replaces them
|
100
100
|
#with 'swear' characters,such as '#$@!%&'
|
101
101
|
def replace(value, dict)
|
102
|
-
|
102
|
+
dict.each do |word|
|
103
103
|
value.to_s.gsub!(/#{word}/, word.split(//).map{|c| c = Cleaner::Data.replacement_chars.shuffle[0]}.join(''))
|
104
104
|
end
|
105
105
|
value
|
Binary file
|
data/test/cleanerupper_test.rb
CHANGED
@@ -2,7 +2,8 @@ require File.join(File.dirname(__FILE__), 'test_helper')
|
|
2
2
|
|
3
3
|
Cleaner::Data.dictionaries = {
|
4
4
|
:words => ["scramble_test", "remove_test", "replace_test", "custom_test", "default_test"],
|
5
|
-
:animals => ["cat_test", "dog_test", "fish_test"]
|
5
|
+
:animals => ["cat_test", "dog_test", "fish_test"],
|
6
|
+
:furniture => ["bed_test", "chair_test"]
|
6
7
|
}
|
7
8
|
|
8
9
|
class Widget < ActiveRecord::Base
|
@@ -59,6 +60,11 @@ class CustomDictWidget < ActiveRecord::Base
|
|
59
60
|
clean :body, :with => :scramble, :dictionary => :animals
|
60
61
|
end
|
61
62
|
|
63
|
+
class MultiDictWidget < ActiveRecord::Base
|
64
|
+
set_table_name :widgets
|
65
|
+
clean :body, :with => :scramble, :dictionary => [:animals, :furniture]
|
66
|
+
end
|
67
|
+
|
62
68
|
class CleanerupperTest < Test::Unit::TestCase
|
63
69
|
|
64
70
|
def test_automatically_replace
|
@@ -135,8 +141,18 @@ class CleanerupperTest < Test::Unit::TestCase
|
|
135
141
|
w = CustomDictWidget.new(:body => body.dup)
|
136
142
|
w.save
|
137
143
|
w = CustomDictWidget.find(w.id)
|
138
|
-
puts w.body
|
139
144
|
assert w.body != body
|
140
145
|
assert w.body.include?("bird_test")
|
141
146
|
end
|
147
|
+
|
148
|
+
def test_multiple_dictionaries
|
149
|
+
body = "dog_test regular_test bed_test"
|
150
|
+
w = MultiDictWidget.new(:body => body.dup)
|
151
|
+
w.save
|
152
|
+
w = MultiDictWidget.find(w.id)
|
153
|
+
assert w.body != body
|
154
|
+
assert w.body.include?("regular_test")
|
155
|
+
assert !w.body.include?("dog_test")
|
156
|
+
assert !w.body.include?("bed_test")
|
157
|
+
end
|
142
158
|
end
|
data/test/debug.log
CHANGED
@@ -2719,3 +2719,84 @@
|
|
2719
2719
|
[4;35;1mCustomWidget Load (0.5ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 6) [0m
|
2720
2720
|
[4;36;1mScrambleWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper tteusletfd_a body', NULL, NULL)[0m
|
2721
2721
|
[4;35;1mScrambleWidget Load (0.2ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 7) [0m
|
2722
|
+
[4;36;1mSQL (0.4ms)[0m [0;1mselect sqlite_version(*)[0m
|
2723
|
+
[4;35;1mSQL (0.8ms)[0m [0m SELECT name
|
2724
|
+
FROM sqlite_master
|
2725
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
2726
|
+
[0m
|
2727
|
+
[4;36;1mSQL (73.8ms)[0m [0;1mDROP TABLE "widgets"[0m
|
2728
|
+
[4;35;1mSQL (2.9ms)[0m [0mCREATE TABLE "widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(100), "body" varchar(255), "author_name" varchar(100)) [0m
|
2729
|
+
[4;36;1mSQL (0.3ms)[0m [0;1m SELECT name
|
2730
|
+
FROM sqlite_master
|
2731
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
2732
|
+
[0m
|
2733
|
+
[4;35;1mSQL (0.1ms)[0m [0mSELECT version FROM "schema_migrations"[0m
|
2734
|
+
[4;36;1mRemoveWidget Create (0.4ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper test', 'cleanerupper test', NULL)[0m
|
2735
|
+
[4;35;1mRemoveWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 1) [0m
|
2736
|
+
[4;36;1mReplaceWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, 'cleanerupper *%&*@*$@!%%! test', NULL)[0m
|
2737
|
+
[4;35;1mReplaceWidget Load (0.2ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 2) [0m
|
2738
|
+
[4;36;1mScrambleWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper lcs_artetbesm test', NULL, NULL)[0m
|
2739
|
+
[4;35;1mScrambleWidget Load (0.2ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 3) [0m
|
2740
|
+
[4;36;1mCallbackWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('CALLBACK', 'cleanerupper msuotet_cts body', NULL)[0m
|
2741
|
+
[4;35;1mCallbackWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 4) [0m
|
2742
|
+
[4;36;1mCustomDictWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, 'gtdte_os bird_test fehittss_', NULL)[0m
|
2743
|
+
[4;35;1mCustomDictWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 5) [0m
|
2744
|
+
[4;36;1mCustomWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('Custom Value: cleanerupper remove_test title', 'Custom Value: cleanerupper scramble_test body', NULL)[0m
|
2745
|
+
[4;35;1mCustomWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 6) [0m
|
2746
|
+
[4;36;1mScrambleWidget Create (0.1ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper lte_tafetdsu body', NULL, NULL)[0m
|
2747
|
+
[4;35;1mScrambleWidget Load (0.2ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 7) [0m
|
2748
|
+
[4;36;1mSQL (0.4ms)[0m [0;1mselect sqlite_version(*)[0m
|
2749
|
+
[4;35;1mSQL (0.7ms)[0m [0m SELECT name
|
2750
|
+
FROM sqlite_master
|
2751
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
2752
|
+
[0m
|
2753
|
+
[4;36;1mSQL (41.0ms)[0m [0;1mDROP TABLE "widgets"[0m
|
2754
|
+
[4;35;1mSQL (4.1ms)[0m [0mCREATE TABLE "widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(100), "body" varchar(255), "author_name" varchar(100)) [0m
|
2755
|
+
[4;36;1mSQL (0.3ms)[0m [0;1m SELECT name
|
2756
|
+
FROM sqlite_master
|
2757
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
2758
|
+
[0m
|
2759
|
+
[4;35;1mSQL (0.1ms)[0m [0mSELECT version FROM "schema_migrations"[0m
|
2760
|
+
[4;36;1mRemoveWidget Create (0.3ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper test', 'cleanerupper test', NULL)[0m
|
2761
|
+
[4;35;1mRemoveWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 1) [0m
|
2762
|
+
[4;36;1mReplaceWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, 'cleanerupper $@!&*%%@!*!% test', NULL)[0m
|
2763
|
+
[4;35;1mReplaceWidget Load (0.2ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 2) [0m
|
2764
|
+
[4;36;1mScrambleWidget Create (0.3ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper reteml_scbast test', NULL, NULL)[0m
|
2765
|
+
[4;35;1mScrambleWidget Load (0.4ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 3) [0m
|
2766
|
+
[4;36;1mCallbackWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('CALLBACK', 'cleanerupper tsocste_tum body', NULL)[0m
|
2767
|
+
[4;35;1mCallbackWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 4) [0m
|
2768
|
+
[4;36;1mCustomDictWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, 'tst_oged bird_test si_hfetst', NULL)[0m
|
2769
|
+
[4;35;1mCustomDictWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 5) [0m
|
2770
|
+
[4;36;1mCustomWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('Custom Value: cleanerupper remove_test title', 'Custom Value: cleanerupper scramble_test body', NULL)[0m
|
2771
|
+
[4;35;1mCustomWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 6) [0m
|
2772
|
+
[4;36;1mScrambleWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper etatl_sedfut body', NULL, NULL)[0m
|
2773
|
+
[4;35;1mScrambleWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 7) [0m
|
2774
|
+
[4;36;1mMultiDictWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, 'tetdos_g regular_test ebted_st', NULL)[0m
|
2775
|
+
[4;36;1mSQL (0.7ms)[0m [0;1mselect sqlite_version(*)[0m
|
2776
|
+
[4;35;1mSQL (0.8ms)[0m [0m SELECT name
|
2777
|
+
FROM sqlite_master
|
2778
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
2779
|
+
[0m
|
2780
|
+
[4;36;1mSQL (71.9ms)[0m [0;1mDROP TABLE "widgets"[0m
|
2781
|
+
[4;35;1mSQL (3.2ms)[0m [0mCREATE TABLE "widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(100), "body" varchar(255), "author_name" varchar(100)) [0m
|
2782
|
+
[4;36;1mSQL (0.3ms)[0m [0;1m SELECT name
|
2783
|
+
FROM sqlite_master
|
2784
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
2785
|
+
[0m
|
2786
|
+
[4;35;1mSQL (0.1ms)[0m [0mSELECT version FROM "schema_migrations"[0m
|
2787
|
+
[4;36;1mRemoveWidget Create (0.3ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper test', 'cleanerupper test', NULL)[0m
|
2788
|
+
[4;35;1mRemoveWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 1) [0m
|
2789
|
+
[4;36;1mReplaceWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, 'cleanerupper !&%@$%!!*@*@ test', NULL)[0m
|
2790
|
+
[4;35;1mReplaceWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 2) [0m
|
2791
|
+
[4;36;1mScrambleWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper lascbe_tetmrs test', NULL, NULL)[0m
|
2792
|
+
[4;35;1mScrambleWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 3) [0m
|
2793
|
+
[4;36;1mCallbackWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('CALLBACK', 'cleanerupper tm_setcstuo body', NULL)[0m
|
2794
|
+
[4;35;1mCallbackWidget Load (0.2ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 4) [0m
|
2795
|
+
[4;36;1mCustomDictWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, '_tedsogt bird_test eifths_st', NULL)[0m
|
2796
|
+
[4;35;1mCustomDictWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 5) [0m
|
2797
|
+
[4;36;1mCustomWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('Custom Value: cleanerupper remove_test title', 'Custom Value: cleanerupper scramble_test body', NULL)[0m
|
2798
|
+
[4;35;1mCustomWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 6) [0m
|
2799
|
+
[4;36;1mScrambleWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper tdtaflt_suee body', NULL, NULL)[0m
|
2800
|
+
[4;35;1mScrambleWidget Load (0.2ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 7) [0m
|
2801
|
+
[4;36;1mMultiDictWidget Create (0.2ms)[0m [0;1mINSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, 'stdotge_ regular_test tb_edtse', NULL)[0m
|
2802
|
+
[4;35;1mMultiDictWidget Load (0.3ms)[0m [0mSELECT * FROM "widgets" WHERE ("widgets"."id" = 8) [0m
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mike Trpcic
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-20 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- ./pkg/cleanerupper-0.0.0.gem
|
37
37
|
- ./pkg/cleanerupper-0.1.0.gem
|
38
38
|
- ./pkg/cleanerupper-0.1.1.gem
|
39
|
+
- ./pkg/cleanerupper-0.2.0.gem
|
39
40
|
- ./rails/init.rb
|
40
41
|
- ./tasks/cleanerupper_tasks.rake
|
41
42
|
- ./test/cleanerupper_test.rb
|