Class: Brillo::Config
- Inherits:
-
Object
- Object
- Brillo::Config
- Defined in:
- lib/brillo/config.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#compress ⇒ Object
Returns the value of attribute compress.
-
#db ⇒ Object
Returns the value of attribute db.
-
#klass_association_map ⇒ Object
Returns the value of attribute klass_association_map.
-
#obfuscations ⇒ Object
Returns the value of attribute obfuscations.
-
#recreate_db ⇒ Object
Returns the value of attribute recreate_db.
-
#transfer_config ⇒ Object
Returns the value of attribute transfer_config.
Instance Method Summary collapse
- #adapter ⇒ Object
- #add_obfuscation(name, scrubber) ⇒ Object
- #add_tactic(name, tactic) ⇒ Object
- #app_tmp ⇒ Object
- #compressed_dump_path ⇒ Object
- #compressed_filename ⇒ Object
- #dump_filename ⇒ Object
- #dump_path ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
-
#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.
-
#transferrer ⇒ Object
TODO support other transfer systems.
- #verify! ⇒ Object
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( = {}) @app_name = .fetch(:name) @klass_association_map = [:explore] || {} @compress = .fetch(:compress, true) @recreate_db = .fetch(:recreate_db, true) @transfer_config = Transferrer::Config.new(**.fetch(:transfer, {})) @obfuscations = parse_obfuscations([:obfuscations] || {}) rescue KeyError => e raise ConfigParseError, e end |
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name.
3 4 5 |
# File 'lib/brillo/config.rb', line 3 def app_name @app_name end |
#compress ⇒ Object
Returns the value of attribute compress.
3 4 5 |
# File 'lib/brillo/config.rb', line 3 def compress @compress end |
#db ⇒ Object
Returns the value of attribute db.
3 4 5 |
# File 'lib/brillo/config.rb', line 3 def db @db end |
#klass_association_map ⇒ Object
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 |
#obfuscations ⇒ Object
Returns the value of attribute obfuscations.
3 4 5 |
# File 'lib/brillo/config.rb', line 3 def obfuscations @obfuscations end |
#recreate_db ⇒ Object
Returns the value of attribute recreate_db.
3 4 5 |
# File 'lib/brillo/config.rb', line 3 def recreate_db @recreate_db end |
#transfer_config ⇒ Object
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
#adapter ⇒ Object
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_tmp ⇒ Object
36 37 38 |
# File 'lib/brillo/config.rb', line 36 def app_tmp Rails.root.join "tmp" end |
#compressed_dump_path ⇒ Object
52 53 54 |
# File 'lib/brillo/config.rb', line 52 def compressed_dump_path app_tmp + compressed_filename end |
#compressed_filename ⇒ Object
44 45 46 |
# File 'lib/brillo/config.rb', line 44 def compressed_filename compress ? "#{dump_filename}.gz" : dump_filename end |
#dump_filename ⇒ Object
40 41 42 |
# File 'lib/brillo/config.rb', line 40 def dump_filename "#{app_name}-scrubbed.dmp" end |
#dump_path ⇒ Object
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 |
#transferrer ⇒ Object
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 |