Class: Mysql2psql::Config
- Inherits:
-
ConfigBase
- Object
- ConfigBase
- Mysql2psql::Config
- Defined in:
- lib/mysql2psql/config.rb
Instance Attribute Summary
Attributes inherited from ConfigBase
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(configfilepath, generate_default_if_not_found = true) ⇒ Config
constructor
A new instance of Config.
- #reset_configfile(filepath) ⇒ Object
Methods inherited from ConfigBase
Constructor Details
#initialize(configfilepath, generate_default_if_not_found = true) ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mysql2psql/config.rb', line 7 def initialize(configfilepath, generate_default_if_not_found = true) unless File.exists?(configfilepath) reset_configfile(configfilepath) if generate_default_if_not_found if File.exists?(configfilepath) raise Mysql2psql::ConfigurationFileInitialized.new("\n No configuration file found. A new file has been initialized at: #{configfilepath} Please review the configuration and retry..\n\n\n") else raise Mysql2psql::ConfigurationFileNotFound.new("cannot load config file #{configfilepath}") end end super(configfilepath) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Mysql2psql::ConfigBase
Class Method Details
.template(to_filename = nil, include_tables = [], exclude_tables = [], supress_data = false, supress_ddl = false, force_truncate = false) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/mysql2psql/config.rb', line 30 def self.template(to_filename = nil, include_tables = [], exclude_tables = [], supress_data = false, supress_ddl = false, force_truncate = false) configtext = <<EOS mysql: hostname: localhost port: 3306 socket: /tmp/mysql.sock username: mysql2psql password: database: mysql2psql_test destination: # if file is given, output goes to file, else postgres file: #{ to_filename ? to_filename : ''} postgres: hostname: localhost port: 5432 username: mysql2psql password: database: mysql2psql_test # if tables is given, only the listed tables will be converted. leave empty to convert all tables. #tables: #- table1 #- table2 EOS if include_tables.length>0 configtext += "\ntables:\n" include_tables.each do |t| configtext += "- #{t}\n" end end configtext += <<EOS # if exclude_tables is given, exclude the listed tables from the conversion. #exclude_tables: #- table3 #- table4 EOS if exclude_tables.length>0 configtext += "\nexclude_tables:\n" exclude_tables.each do |t| configtext += "- #{t}\n" end end if !supress_data.nil? configtext += <<EOS # if supress_data is true, only the schema definition will be exported/migrated, and not the data supress_data: #{supress_data} EOS end if !supress_ddl.nil? configtext += <<EOS # if supress_ddl is true, only the data will be exported/imported, and not the schema supress_ddl: #{supress_ddl} EOS end if !force_truncate.nil? configtext += <<EOS # if force_truncate is true, forces a table truncate before table loading force_truncate: #{force_truncate} EOS end configtext end |
Instance Method Details
#reset_configfile(filepath) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/mysql2psql/config.rb', line 22 def reset_configfile(filepath) file = File.new(filepath,'w') self.class.template.each_line do | line| file.puts line end file.close end |