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


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

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#generate_whitelist_script(configuration_hash) ⇒ Object


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

def generate_whitelist_script(configuration_hash)

  @configuration_hash = configuration_hash
  @ar_object = ActiveRecord::Base.establish_connection(@configuration_hash)

  @tables = @ar_object.connection.tables

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

  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