Class: Arxutils::Dbutil::Dbinit
- Inherits:
-
Object
- Object
- Arxutils::Dbutil::Dbinit
- Defined in:
- lib/arxutils/dbutil/dbinit.rb
Instance Attribute Summary collapse
-
#dbconfig_dest_fname ⇒ Object
Returns the value of attribute dbconfig_dest_fname.
-
#dbconfig_dest_path ⇒ Object
Returns the value of attribute dbconfig_dest_path.
-
#dbconfig_src_fname ⇒ Object
Returns the value of attribute dbconfig_src_fname.
-
#dbconfig_src_path ⇒ Object
Returns the value of attribute dbconfig_src_path.
-
#migrate_dir ⇒ Object
Returns the value of attribute migrate_dir.
Instance Method Summary collapse
-
#initialize(migrate_base_dir, src_config_dir, dbconfig, log_fname, forced = false) ⇒ Dbinit
constructor
A new instance of Dbinit.
- #setup ⇒ Object
Constructor Details
#initialize(migrate_base_dir, src_config_dir, dbconfig, log_fname, forced = false) ⇒ Dbinit
Returns a new instance of Dbinit.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/arxutils/dbutil/dbinit.rb', line 19 def initialize( migrate_base_dir , src_config_dir , dbconfig , log_fname, forced = false ) @db_dir = dbconfig[:db_dir] @src_config_dir = src_config_dir @dest_config_dir = "config" @dbconfig_dest_fname = "#{dbconfig[:kind]}.yaml" @dbconfig_src_fname = "#{dbconfig[:kind]}.tmpl" @dbconfig_dest_path = File.join( @dest_config_dir , @dbconfig_dest_fname) @dbconfig_src_path = File.join(@src_config_dir , @dbconfig_src_fname) @log_fname = log_fname if @db_dir and @log_fname @log_path = File.join( @db_dir , @log_fname ) @migrate_dir = File.join( @db_dir , migrate_base_dir ) end FileUtils.mkdir_p( @db_dir ) if @db_dir FileUtils.mkdir_p( @migrate_dir ) if @migrate_dir FileUtils.mkdir_p( @dest_config_dir ) if forced FileUtils.rm( Dir.glob( File.join( @migrate_dir , "*"))) if @migrate_dir FileUtils.rm( Dir.glob( File.join( @dest_config_dir , "*"))) end end |
Instance Attribute Details
#dbconfig_dest_fname ⇒ Object
Returns the value of attribute dbconfig_dest_fname.
17 18 19 |
# File 'lib/arxutils/dbutil/dbinit.rb', line 17 def dbconfig_dest_fname @dbconfig_dest_fname end |
#dbconfig_dest_path ⇒ Object
Returns the value of attribute dbconfig_dest_path.
17 18 19 |
# File 'lib/arxutils/dbutil/dbinit.rb', line 17 def dbconfig_dest_path @dbconfig_dest_path end |
#dbconfig_src_fname ⇒ Object
Returns the value of attribute dbconfig_src_fname.
17 18 19 |
# File 'lib/arxutils/dbutil/dbinit.rb', line 17 def dbconfig_src_fname @dbconfig_src_fname end |
#dbconfig_src_path ⇒ Object
Returns the value of attribute dbconfig_src_path.
17 18 19 |
# File 'lib/arxutils/dbutil/dbinit.rb', line 17 def dbconfig_src_path @dbconfig_src_path end |
#migrate_dir ⇒ Object
Returns the value of attribute migrate_dir.
17 18 19 |
# File 'lib/arxutils/dbutil/dbinit.rb', line 17 def migrate_dir @migrate_dir end |
Instance Method Details
#setup ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/arxutils/dbutil/dbinit.rb', line 42 def setup puts ENV['ENV'] dbconfig = YAML.load( File.read( @dbconfig_dest_path ) ) puts dbconfig[ ENV['ENV'] ] ActiveRecord::Base.establish_connection(dbconfig[ENV['ENV']]) ActiveRecord::Base.logger = Logger.new( @log_path ) end |