acts_as_scrubbable 0.0.2 → 0.0.3

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: 4234c5c4fc17e4e56651d0af73d4d8618479722f
4
- data.tar.gz: 1cced9cfe5e6c3a798326778370f10ca34332aab
3
+ metadata.gz: 2b879327a376524d60458ad12c6a7688b5d85baf
4
+ data.tar.gz: 52411d6ea51c0a3f4484ef09c96195cea42bae9f
5
5
  SHA512:
6
- metadata.gz: 4ce7605fe9907554adcab36eec514ed28320062e778f012a321ecf6dece86ed8249d1401632156c615b21ef4e816677f04f76cd38a7929bb9036aa0d07700352
7
- data.tar.gz: 5ec1de24a3bedf7497b6d33205811800a8a7736b0c23b03a98eb26d862971e15e5ba338a682019bb72b9d22c89b9e96642353117f51ba741080b252a1695fd38
6
+ metadata.gz: bb3958c928fc147ab33945e5e045db624715e584c72d15eb4b86718b9da3613730c0389ec17b567b24a7fcb0b200849cd1b7e4cfe923143bc508d2d4f88fe5db
7
+ data.tar.gz: e49d143b35922305445915b2bc88138399cdb10e6670ee801fd3b2e4d2f3824332cefcf1e6ca188caa5fd6f458f205152f7f457883803d6315295e5ce9c13a17
data/README.md CHANGED
@@ -53,10 +53,15 @@ I, [2015-11-05T14:09:25.615155 #64194] INFO -- : Scrub Complete!
53
53
 
54
54
  ### Extending
55
55
 
56
- You may find the need to extend or add additional generators
56
+ You may find the need to extend or add additional generators or an after_hook
57
57
 
58
58
  ```ruby
59
59
  ActsAsScrubbable.configure do |c|
60
60
  c.add :email_with_prefix, -> { "prefix-#{Faker::Internet.email}" }
61
+
62
+ c.after_hook do
63
+ puts "Running after commit"
64
+ ActiveRecord::Base.connection.execute("SELECT * FROM FOO")
65
+ end
61
66
  end
62
67
  ```
@@ -11,10 +11,19 @@ module ActsAsScrubbable
11
11
  autoload :Scrub
12
12
  autoload :VERSION
13
13
 
14
+
14
15
  def self.configure(&block)
15
16
  yield self
16
17
  end
17
18
 
19
+ def self.after_hook(&block)
20
+ @after_hook = block
21
+ end
22
+
23
+ def self.execute_after_hook
24
+ @after_hook.call if @after_hook
25
+ end
26
+
18
27
  def self.add(key, value)
19
28
  ActsAsScrubbable.scrub_map[key] = value
20
29
  end
@@ -26,15 +35,21 @@ module ActsAsScrubbable
26
35
  :first_name => -> { Faker::Name.first_name },
27
36
  :last_name => -> { Faker::Name.first_name },
28
37
  :middle_name => -> { Faker::Name.name },
29
- :full_name => -> { Faker::Name.name },
38
+ :name => -> { Faker::Name.name },
30
39
  :email => -> { Faker::Internet.email },
31
40
  :name_title => -> { Faker::Name.title },
32
41
  :company_name => -> { Faker::Company.name },
33
42
  :street_address => -> { Faker::Address.street_address },
34
43
  :secondary_address => -> { Faker::Address.secondary_address },
44
+ :zip_code => -> { Faker::Address.zip_code },
45
+ :state_abbr => -> { Faker::Address.state_abbr },
46
+ :state => -> { Faker::Address.state },
35
47
  :city => -> { Faker::Address.city },
36
48
  :latitude => -> { Faker::Address.latitude },
37
- :longitude => -> { Faker::Address.longitude }
49
+ :longitude => -> { Faker::Address.longitude },
50
+ :username => -> { Faker::Internet.user_name },
51
+ :boolean => -> { [true, false ].sample },
52
+ :school => -> { Faker::University.name }
38
53
  }
39
54
  end
40
55
  end
@@ -5,10 +5,17 @@ module ActsAsScrubbable
5
5
  if self.class.scrubbable?
6
6
  _updates = {}
7
7
 
8
- scrubbable_fields.each do |key, value|
9
- next if self.send(key).blank?
8
+ scrubbable_fields.each do |_field, value|
9
+ unless self.respond_to?(_field)
10
+ raise ArgumentError, "#{self.class} do not respond to #{_field}"
11
+ end
12
+ next if self.send(_field).blank?
10
13
 
11
- _updates[key] = ActsAsScrubbable.scrub_map[value].call
14
+ if ActsAsScrubbable.scrub_map.keys.include?(value)
15
+ _updates[_field] = ActsAsScrubbable.scrub_map[value].call
16
+ else
17
+ puts "Undefined scrub: #{value} for #{self.class}#{_field}"
18
+ end
12
19
  end
13
20
 
14
21
  self.update_columns(_updates) unless _updates.empty?
@@ -20,18 +20,26 @@ namespace :scrub do
20
20
  @logger.warn "Scrubbing classes".red
21
21
 
22
22
  Rails.application.eager_load! # make sure all the classes are loaded
23
+
24
+ @total_scrubbed = 0
25
+
23
26
  ActiveRecord::Base.descendants.sort_by{|d| d.to_s }.each do |ar_class|
24
27
  next unless ar_class.scrubbable?
25
28
 
26
- @logger.info "Scrubbing #{ar_class}".green
27
-
29
+ scrubbed_count = 0
28
30
  ar_class.find_in_batches do |batch|
29
31
  batch.each do |obj|
30
32
  obj.scrub!
33
+ scrubbed_count += 1
31
34
  end
32
35
  end
33
-
36
+ @logger.info "Scrubbed #{scrubbed_count} #{ar_class} objects".green
37
+ @total_scrubbed += scrubbed_count
34
38
  end
39
+
40
+ ActsAsScrubbable.execute_after_hook
41
+
42
+ @logger.info "#{@total_scrubbed} scrubbed objects".blue
35
43
  @logger.info "Scrub Complete!".white
36
44
  end
37
45
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsScrubbable
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_scrubbable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samer Masry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-05 00:00:00.000000000 Z
11
+ date: 2015-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport