class Brillo::Config

Attributes

app_name[RW]
compress[RW]
db[RW]
klass_association_map[RW]
obfuscations[RW]
recreate_db[RW]
transfer_config[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/brillo/config.rb, line 5
def initialize(options = {})
  @app_name =               options.fetch(:name)
  @klass_association_map =  options[:explore] || {}
  @compress =               options.fetch(:compress,  true)
  @recreate_db =            options.fetch(:recreate_db,  true)
  @transfer_config =        Transferrer::Config.new(**options.fetch(:transfer, {}))
  @obfuscations =           parse_obfuscations(options[:obfuscations] || {})
rescue KeyError => e
  raise ConfigParseError, e
end

Public Instance Methods

adapter() click to toggle source
# File lib/brillo/config.rb, line 65
def adapter
  case db["adapter"].to_sym
  when :mysql2
    Adapter::MySQL.new(db)
  when :postgresql
    Adapter::Postgres.new(db)
  else
    raise ConfigParseError, "Unsupported DB adapter #{db["adapter"]}"
  end
end
add_obfuscation(name, scrubber) click to toggle source
# File lib/brillo/config.rb, line 28
def add_obfuscation(name, scrubber)
  Scrubber::SCRUBBERS[name] = scrubber
end
add_tactic(name, tactic) click to toggle source
# File lib/brillo/config.rb, line 32
def add_tactic(name, tactic)
  Scrubber::TACTICS[name] = tactic
end
app_tmp() click to toggle source
# File lib/brillo/config.rb, line 36
def app_tmp
  Rails.root.join "tmp"
end
compressed_dump_path() click to toggle source
# File lib/brillo/config.rb, line 52
def compressed_dump_path
  app_tmp + compressed_filename
end
compressed_filename() click to toggle source
# File lib/brillo/config.rb, line 44
def compressed_filename
  compress ? "#{dump_filename}.gz" : dump_filename
end
dump_filename() click to toggle source
# File lib/brillo/config.rb, line 40
def dump_filename
  "#{app_name}-scrubbed.dmp"
end
dump_path() click to toggle source
# File lib/brillo/config.rb, line 48
def dump_path
  app_tmp + dump_filename
end
parse_obfuscations(obfuscations) click to toggle source

Convert generic cross table obfuscations to symbols so Polo parses them correctly :“my_table.field” => “my_table.field” :my_field => :my_field

# File lib/brillo/config.rb, line 79
def parse_obfuscations(obfuscations)
  obfuscations.each_pair.with_object({}) do |field_and_strategy, hash|
    field, strategy = field_and_strategy
    strategy = strategy.to_sym
    field.to_s.match(/\./) ? hash[field.to_s] = strategy : hash[field] = strategy
  end
end
transferrer() click to toggle source

TODO support other transfer systems

# File lib/brillo/config.rb, line 61
def transferrer
  Transferrer::S3.new(self)
end
verify!() click to toggle source
# File lib/brillo/config.rb, line 16
def verify!
  @obfuscations.each do |field, strategy|
    next if Scrubber::SCRUBBERS[strategy]
    raise ConfigParseError, "Scrub strategy '#{strategy}' not found, but required by '#{field}'"
  end
  @klass_association_map.each do |klass, _|
    next if klass.to_s.camelize.safe_constantize
    raise ConfigParseError, "Class #{klass} not found"
  end
  self
end