Class: Arxutils::Migrate

Inherits:
Object
  • Object
show all
Defined in:
lib/arxutils/migrate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db_dir, migrate_dir, config_dir, dbconfig, log_fname, forced = false) ⇒ Migrate

Returns a new instance of Migrate.



25
26
27
28
29
30
31
32
33
34
# File 'lib/arxutils/migrate.rb', line 25

def initialize( db_dir , migrate_dir , config_dir , dbconfig, log_fname, forced = false )
  @dbinit = Dbutil::Dbinit.new( db_dir , migrate_dir , config_dir , dbconfig, log_fname, forced )
  @dbconfig_dest_path = @dbinit.dbconfig_dest_path
  @dbconfig_src_path = @dbinit.dbconfig_src_path
  @dbconfig_src_fname = @dbinit.dbconfig_src_fname

  @migrate_dir = migrate_dir
  @src_path = Arxutils.templatedir
  @src_config_path = Arxutils.configdir
end

Instance Attribute Details

#dbconfig_dest_fnameObject

Returns the value of attribute dbconfig_dest_fname.



9
10
11
# File 'lib/arxutils/migrate.rb', line 9

def dbconfig_dest_fname
  @dbconfig_dest_fname
end

#dbconfig_dest_pathObject

Returns the value of attribute dbconfig_dest_path.



9
10
11
# File 'lib/arxutils/migrate.rb', line 9

def dbconfig_dest_path
  @dbconfig_dest_path
end

#dbconfig_src_fnameObject

Returns the value of attribute dbconfig_src_fname.



9
10
11
# File 'lib/arxutils/migrate.rb', line 9

def dbconfig_src_fname
  @dbconfig_src_fname
end

#dbconfig_src_pathObject

Returns the value of attribute dbconfig_src_path.



9
10
11
# File 'lib/arxutils/migrate.rb', line 9

def dbconfig_src_path
  @dbconfig_src_path
end

#dbinitObject

Returns the value of attribute dbinit.



9
10
11
# File 'lib/arxutils/migrate.rb', line 9

def dbinit
  @dbinit
end

Class Method Details

.migrate(data_ary, idx, dbconfig, forced) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/arxutils/migrate.rb', line 11

def Migrate.migrate( data_ary , idx , dbconfig , forced )
  src_config_dir = Arxutils.configdir
  mig = Migrate.new(Dbutil::DB_DIR, Dbutil::MIGRATE_DIR , src_config_dir , dbconfig, Dbutil::DATABASELOG, forced )
  mig.make_dbconfig( data_ary[idx] )
  
  data_ary.reduce(0) do |next_num , x| 
    mig.make( next_num , x )
  end

  Dbutil::DbMgr.setup( mig.dbinit )

  mig.migrate
end

Instance Method Details

#convert(data, src_dir, src_fname) ⇒ Object



36
37
38
39
# File 'lib/arxutils/migrate.rb', line 36

def convert( data , src_dir , src_fname )
  arx = Arx.new( data , File.join( src_dir, src_fname ) )
  arx.create
end

#make(next_num, data) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/arxutils/migrate.rb', line 48

def make( next_num , data )
  data[:flist].reduce(next_num) do |idy , x|
    idy += 10
    content = convert( data , @src_path , "#{x}.tmpl" )
    case x
    when "base" , "noitem"
      additional = ""
    else
      additional = x
    end
    fname = File.join( @migrate_dir , sprintf("%03d_create_%s%s.rb" , idy , additional , data[:classname_downcase]) )
    p fname
    File.open( fname , 'w' , {:encoding => Encoding::UTF_8}){ |f|
      f.puts( content )
    }
    idy
  end
end

#make_dbconfig(data) ⇒ Object



41
42
43
44
45
46
# File 'lib/arxutils/migrate.rb', line 41

def make_dbconfig( data )
  content = convert( data , @src_config_path , @dbconfig_src_fname )
  File.open( @dbconfig_dest_path , 'w' , {:encoding => Encoding::UTF_8}){ |f|
    f.puts( content )
  }
end

#migrateObject



67
68
69
# File 'lib/arxutils/migrate.rb', line 67

def migrate
  ActiveRecord::Migrator.migrate(@migrate_dir ,  ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
end