acts_as_scrubbable 0.0.9 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a30100c4a8d86460a2dd192d3b9c2b14dccc616
4
- data.tar.gz: 106dd64cccef9f5066afcfa647ec5fded235ca69
3
+ metadata.gz: 6390e59999100796cea61137d66569b2bf71378f
4
+ data.tar.gz: b263aaf6593de485d4b90d382154e6431f0eec27
5
5
  SHA512:
6
- metadata.gz: cc200514ab242f7678bd778c49a7bab8e5ed57a048b7aa44c7c65137684f744d7a31f11e16f60e0d3acfa82b3900586650c2b266cd39ebd9e30830ea81f562d4
7
- data.tar.gz: 6c011342d162f353c03c7ac238691cbc6073ff960cf740be703e51e44a0e886281c6a4fbccadcc8784ee925583c7bf34276abce1d2579a951d07eac19542b2a4
6
+ metadata.gz: f2627b29f34e4a34064e93a922587c2021fa15da1e2d6656bd6d6a8af47732a36adee12cf79218d0eb3185f605217e8fb6cee58e4f274e03db2583c7ae6f11e3
7
+ data.tar.gz: 5f3b8997f284cfb89be881c0a61be908224d47e9016fcbd4e4057d74a580ef6d9f9c451774acaede3c186965b1c86d7d994e472a472ae4b715caec085d060f35
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acts_as_scrubbable (0.0.7)
4
+ acts_as_scrubbable (0.1.0)
5
5
  activerecord (~> 4.1)
6
6
  activesupport (~> 4.1)
7
7
  faker (~> 1.4)
data/README.md CHANGED
@@ -44,16 +44,22 @@ end
44
44
 
45
45
 
46
46
  ### To run
47
+
48
+ The confirmation message will be the db host
49
+
47
50
  ```
48
51
  rake scrub
49
52
 
50
53
  ....
51
- Type SCRUB to continue.
52
- SCRUB
53
- W, [2015-11-05T14:09:20.900771 #64194] WARN -- : Scrubbing classes
54
- I, [2015-11-05T14:09:24.228012 #64194] INFO -- : Scrubbing ClassToScrub
54
+ 2015-11-19 10:52:51 -0800: [WARN] - Please verify the information below to continue
55
+ 2015-11-19 10:52:51 -0800: [WARN] - Host: 127.0.0.1
56
+ 2015-11-19 10:52:51 -0800: [WARN] - Database: blog_development
57
+ Type '127.0.0.1' to continue.
58
+ -> 127.0.0.1
59
+ 2015-11-19 10:52:51 -0800: [WARN] -- : Scrubbing classes
60
+ 2015-11-19 10:52:51 -0800: [WARN] -- : Scrubbing ClassToScrub
55
61
  ...
56
- I, [2015-11-05T14:09:25.615155 #64194] INFO -- : Scrub Complete!
62
+ 2015-11-19 10:52:51 -0800: [WARN] -- : Scrub Complete!
57
63
 
58
64
  ```
59
65
 
@@ -63,6 +69,12 @@ In the case you are automating the rake task and want to skip the confirmation
63
69
  rake scrub SKIP_CONFIRM=true
64
70
  ```
65
71
 
72
+ If you want to limit the classes you to be scrubbed you can set the `SCRUB_CLASSES` variable
73
+
74
+ ```
75
+ rake scrub SCRUB_CLASSES=Blog,Post
76
+ ```
77
+
66
78
 
67
79
 
68
80
  ### Extending
@@ -7,18 +7,17 @@ module ActsAsScrubbable
7
7
  end
8
8
 
9
9
 
10
- def acts_as_scrubbable(*scrubbable_fields)
10
+ def acts_as_scrubbable(*scrubbable_fields, **mapped_fields)
11
11
 
12
12
  class_attribute :scrubbable_fields
13
13
 
14
14
  self.scrubbable_fields = {}
15
-
16
15
  scrubbable_fields.each do |_field|
17
- if _field.is_a? Hash
18
- self.scrubbable_fields[_field.keys.first] = _field.values.first
19
- else
20
- self.scrubbable_fields[_field] = _field
21
- end
16
+ self.scrubbable_fields[_field] = _field
17
+ end
18
+
19
+ mapped_fields.each do |_field|
20
+ self.scrubbable_fields[_field.first] = _field.last
22
21
  end
23
22
 
24
23
  class_eval do
@@ -11,14 +11,26 @@ namespace :scrub do
11
11
  require 'logger'
12
12
  require 'parallel'
13
13
 
14
+
14
15
  include Term::ANSIColor
15
16
 
16
17
  @logger = Logger.new($stdout)
18
+ @logger.formatter = proc do |severity, datetime, progname, msg|
19
+ "#{datetime}: [#{severity}] - #{msg}\n"
20
+ end
21
+
22
+ db_host = ActiveRecord::Base.connection_config[:host]
23
+ db_name = ActiveRecord::Base.connection_config[:database]
24
+
25
+ @logger.warn "Please verify the information below to continue".red
26
+ @logger.warn "Host: ".red + " #{db_host}".white
27
+ @logger.warn "Database: ".red + "#{db_name}".white
17
28
 
18
29
  unless ENV["SKIP_CONFIRM"] == "true"
19
- answer = ask("Type SCRUB to continue.".red)
20
- unless answer == "SCRUB"
21
- puts "exiting ...".red
30
+
31
+ answer = ask("Type '#{db_host}' to continue. \n".red + '-> '.white)
32
+ unless answer == db_host
33
+ @logger.error "exiting ...".red
22
34
  exit
23
35
  end
24
36
  end
@@ -30,6 +42,18 @@ namespace :scrub do
30
42
  @total_scrubbed = 0
31
43
 
32
44
  ar_classes = ActiveRecord::Base.descendants.select{|d| d.scrubbable? }.sort_by{|d| d.to_s }
45
+
46
+
47
+ # if the ENV variable is set
48
+
49
+ unless ENV["SCRUB_CLASSES"].blank?
50
+ class_list = ENV["SCRUB_CLASSES"].split(",")
51
+ class_list = class_list.map {|_class_str| _class_str.constantize }
52
+ ar_classes = ar_classes & class_list
53
+ end
54
+
55
+ @logger.info "Srubbable Classes: #{ar_classes.join(', ')}".white
56
+
33
57
  Parallel.each(ar_classes) do |ar_class|
34
58
 
35
59
  # Removing any find or initialize callbacks from model
@@ -1,3 +1,3 @@
1
1
  module ActsAsScrubbable
2
- VERSION = '0.0.9'
2
+ VERSION = '0.1.0'
3
3
  end
data/spec/db/schema.rb CHANGED
@@ -3,6 +3,7 @@ ActiveRecord::Schema.define(version: 20150421224501) do
3
3
  create_table "scrubbable_models", force: true do |t|
4
4
  t.string "first_name"
5
5
  t.string "address1"
6
+ t.string "lat"
6
7
  end
7
8
 
8
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_scrubbable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samer Masry