Class: Brillo::Scrubber
- Inherits:
-
Object
- Object
- Brillo::Scrubber
- Includes:
- Helpers::ExecHelper, Logger
- Defined in:
- lib/brillo/scrubber.rb
Overview
Responsible for creating a fresh scrubbed SQL copy of the database, as specified via config, and uploading to S3
Constant Summary collapse
- JUMBLE_PRNG =
Random.new
- LATEST_LIMIT =
1_000
- SCRUBBERS =
Define some procs as scrubbing strategies for Polo
{ default_time: ->(t) { t.nil? ? Time.now.to_s(:sql) : t }, email: ->(e) { Digest::MD5.hexdigest(e) + "@example.com".freeze }, jumble: ->(j) { j.downcase.chars.shuffle!(random: JUMBLE_PRNG.clone).join }, # strips extensions phone: ->(n) { n = n.split(' ').first; n && n.length > 9 ? n[0..-5] + n[-1] + n[-2] + n[-3] + n[-4] : n}, name: ->(n) { n.downcase.split(' ').map do |word| word.chars.shuffle!(random: JUMBLE_PRNG.clone).join end.each(&:capitalize!).join(' ') }, }
- TACTICS =
{ latest: -> (klass) { klass.order("#{klass.primary_key} desc").limit(LATEST_LIMIT).pluck(klass.primary_key) }, all: -> (klass) { klass.pluck(klass.primary_key) } }
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#transferrer ⇒ Object
readonly
Returns the value of attribute transferrer.
Instance Method Summary collapse
- #dump_structure_and_migrations ⇒ Object
- #explore_all_classes ⇒ Object
-
#initialize(config) ⇒ Scrubber
constructor
A new instance of Scrubber.
- #scrub! ⇒ Object
Methods included from Logger
Methods included from Helpers::ExecHelper
Constructor Details
#initialize(config) ⇒ Scrubber
Returns a new instance of Scrubber.
30 31 32 33 |
# File 'lib/brillo/scrubber.rb', line 30 def initialize(config) @config = config @adapter = config.adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
28 29 30 |
# File 'lib/brillo/scrubber.rb', line 28 def adapter @adapter end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
28 29 30 |
# File 'lib/brillo/scrubber.rb', line 28 def config @config end |
#transferrer ⇒ Object (readonly)
Returns the value of attribute transferrer.
28 29 30 |
# File 'lib/brillo/scrubber.rb', line 28 def transferrer @transferrer end |
Instance Method Details
#dump_structure_and_migrations ⇒ Object
44 45 46 47 |
# File 'lib/brillo/scrubber.rb', line 44 def dump_structure_and_migrations return unless config.recreate_db adapter.dump_structure_and_migrations(config) end |
#explore_all_classes ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/brillo/scrubber.rb', line 49 def explore_all_classes File.open(config.dump_path, "a") do |sql_file| sql_file.puts(adapter.header) klass_association_map.each do |klass, | begin klass = deserialize_class(klass) tactic = deserialize_tactic(klass, ) rescue ConfigParseError => e logger.error "Error in brillo.yml: #{e.message}" next end associations = .fetch(:associations, []) explore_class(klass, tactic, associations) do |insert| sql_file.puts(insert) end end ActiveRecord::Base.descendants.each do |klass| sql_file.puts(adapter.(klass)) end sql_file.puts(adapter.) end end |
#scrub! ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/brillo/scrubber.rb', line 35 def scrub! FileUtils.rm config.compressed_filename, force: true configure_polo dump_structure_and_migrations explore_all_classes compress config.transferrer.upload end |