Class: Brillo::Config
- Inherits:
-
Object
- Object
- Brillo::Config
- Defined in:
- lib/brillo/config.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
-
#compress ⇒ Object
readonly
Returns the value of attribute compress.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#klass_association_map ⇒ Object
readonly
Returns the value of attribute klass_association_map.
-
#obfuscations ⇒ Object
readonly
Returns the value of attribute obfuscations.
-
#transfer_config ⇒ Object
readonly
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 |
# File 'lib/brillo/config.rb', line 5 def initialize( = {}) @app_name = .fetch(:name) @klass_association_map = [:explore] || {} @compress = .fetch(:compress, 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 (readonly)
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 (readonly)
Returns the value of attribute compress.
3 4 5 |
# File 'lib/brillo/config.rb', line 3 def compress @compress end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
3 4 5 |
# File 'lib/brillo/config.rb', line 3 def db @db end |
#klass_association_map ⇒ Object (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 |
#obfuscations ⇒ Object (readonly)
Returns the value of attribute obfuscations.
3 4 5 |
# File 'lib/brillo/config.rb', line 3 def obfuscations @obfuscations end |
#transfer_config ⇒ Object (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
#adapter ⇒ Object
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_tmp ⇒ Object
35 36 37 |
# File 'lib/brillo/config.rb', line 35 def app_tmp Rails.root.join "tmp" end |
#compressed_dump_path ⇒ Object
51 52 53 |
# File 'lib/brillo/config.rb', line 51 def compressed_dump_path app_tmp + compressed_filename end |
#compressed_filename ⇒ Object
43 44 45 |
# File 'lib/brillo/config.rb', line 43 def compressed_filename compress ? "#{dump_filename}.gz" : dump_filename end |
#dump_filename ⇒ Object
39 40 41 |
# File 'lib/brillo/config.rb', line 39 def dump_filename "#{app_name}-scrubbed.dmp" end |
#dump_path ⇒ Object
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 |
#transferrer ⇒ Object
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 |