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
# 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)
  @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 (readonly)

Returns the value of attribute app_name.



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

def app_name
  @app_name
end

#compressObject (readonly)

Returns the value of attribute compress.



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

def compress
  @compress
end

#dbObject (readonly)

Returns the value of attribute db.



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

def db
  @db
end

#klass_association_mapObject (readonly)

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 (readonly)

Returns the value of attribute obfuscations.



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

def obfuscations
  @obfuscations
end

#transfer_configObject (readonly)

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



64
65
66
67
68
69
70
71
72
73
# File 'lib/brillo/config.rb', line 64

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



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

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

#add_tactic(name, tactic) ⇒ Object



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

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

#app_tmpObject



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

def app_tmp
  Rails.root.join "tmp"
end

#compressed_dump_pathObject



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

def compressed_dump_path
  app_tmp + compressed_filename
end

#compressed_filenameObject



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

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

#dump_filenameObject



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

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

#dump_pathObject



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

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



78
79
80
81
82
83
84
# File 'lib/brillo/config.rb', line 78

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



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

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

#verify!Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/brillo/config.rb', line 15

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