Class: DataAnon::ThorHelpers::RDBMSDSLGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/thor/helpers/rdbms_dsl_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



8
9
10
# File 'lib/thor/helpers/rdbms_dsl_generator.rb', line 8

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#generate_whitelist_script(configuration_hash) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/thor/helpers/rdbms_dsl_generator.rb', line 12

def generate_whitelist_script(configuration_hash)
  @configuration_hash = configuration_hash
  connection_pool = ActiveRecord::Base.establish_connection(@configuration_hash)
  @connection = connection_pool.lease_connection

  @tables = @connection.tables

  erb = ERB.new(File.new(RDBMSDSLGenerator.source_root + "/../templates/whitelist_template.erb").read, trim_mode: "-")

  File.open("rdbms_whitelist_generated.rb", "w") do |f|
    f.write erb.result(binding)
    f.close
  end
rescue => e
  puts "\e[31mActiverecord was unable to establish a connection to the specified database. Please check the configuration options and try again.\e[0m"
  puts e.backtrace
end