Class: Brillo::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/brillo/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



5
6
7
8
9
10
11
12
13
14
# 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

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



3
4
5
# File 'lib/brillo/config.rb', line 3

def app_name
  @app_name
end

#compressObject

Returns the value of attribute compress.



3
4
5
# File 'lib/brillo/config.rb', line 3

def compress
  @compress
end

#dbObject

Returns the value of attribute db.



3
4
5
# File 'lib/brillo/config.rb', line 3

def db
  @db
end

#klass_association_mapObject

Returns the value of attribute klass_association_map.



3
4
5
# File 'lib/brillo/config.rb', line 3

def klass_association_map
  @klass_association_map
end

#obfuscationsObject

Returns the value of attribute obfuscations.



3
4
5
# File 'lib/brillo/config.rb', line 3

def obfuscations
  @obfuscations
end

#recreate_dbObject

Returns the value of attribute recreate_db.



3
4
5
# File 'lib/brillo/config.rb', line 3

def recreate_db
  @recreate_db
end

#transfer_configObject

Returns the value of attribute transfer_config.



3
4
5
# File 'lib/brillo/config.rb', line 3

def transfer_config
  @transfer_config
end

Instance Method Details

#adapterObject



65
66
67
68
69
70
71
72
73
74
# 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) ⇒ Object



28
29
30
# File 'lib/brillo/config.rb', line 28

def add_obfuscation(name, scrubber)
  Scrubber::SCRUBBERS[name] = scrubber
end

#add_tactic(name, tactic) ⇒ Object



32
33
34
# File 'lib/brillo/config.rb', line 32

def add_tactic(name, tactic)
  Scrubber::TACTICS[name] = tactic
end

#app_tmpObject



36
37
38
# File 'lib/brillo/config.rb', line 36

def app_tmp
  Rails.root.join "tmp"
end

#compressed_dump_pathObject



52
53
54
# File 'lib/brillo/config.rb', line 52

def compressed_dump_path
  app_tmp + compressed_filename
end

#compressed_filenameObject



44
45
46
# File 'lib/brillo/config.rb', line 44

def compressed_filename
  compress ? "#{dump_filename}.gz" : dump_filename
end

#dump_filenameObject



40
41
42
# File 'lib/brillo/config.rb', line 40

def dump_filename
  "#{app_name}-scrubbed.dmp"
end

#dump_pathObject



48
49
50
# File 'lib/brillo/config.rb', line 48

def dump_path
  app_tmp + dump_filename
end

#parse_obfuscations(obfuscations) ⇒ Object

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



79
80
81
82
83
84
85
# 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

#transferrerObject

TODO support other transfer systems



61
62
63
# File 'lib/brillo/config.rb', line 61

def transferrer
  Transferrer::S3.new(self)
end

#verify!Object



16
17
18
19
20
21
22
23
24
25
26
# 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