Module: DataMetaByteSer::VerReads
- Includes:
- DataMetaDom, DataMetaDom::PojoLexer
- Defined in:
- lib/dataMetaByteSer/ver_reads.rb
Overview
Migration tooling.
Class Method Summary collapse
-
.genVerReadSwitch(v1, v2, modelForVer, vers, outRoot) ⇒ Object
Generates Versioned Read switch that channels the read to the proper migration scenario.
Class Method Details
.genVerReadSwitch(v1, v2, modelForVer, vers, outRoot) ⇒ Object
Generates Versioned Read switch that channels the read to the proper migration scenario.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 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 |
# File 'lib/dataMetaByteSer/ver_reads.rb', line 16 def genVerReadSwitch(v1, v2, modelForVer, vers, outRoot) # v1 = mo1.records.values.first.ver.full # v2 = mo2.records.values.first.ver.full mo1 = modelForVer.call(v1) mo2 = modelForVer.call(v2) destDir = outRoot javaPackage = '' # set the scope for the var vars = OpenStruct.new # for template's local variables. ERB does not make them visible to the binding # sort the models by versions out, 2nd to be the latest: raise ArgumentError, "Versions on the model are the same: #{v1}" if v1 == v2 if v1 > v2 model2 = mo1 model1 = mo2 ver1 = v2 ver2 = v1 else model2 = mo2 model1 = mo1 ver1 = v1 ver2 = v2 end puts "Going from ver #{ver1} to #{ver2}" trgE = model2.records.values.first javaPackage, baseName, packagePath = assertNamespace(trgE.name) javaClassName = "Read__Switch_v#{ver1.toVarName}_to_v#{ver2.toVarName}" destDir = File.join(outRoot, packagePath) FileUtils.mkdir_p destDir javaDestFile = File.join(destDir, "#{javaClassName}.java") skippedCount = 0 if File.file?(javaDestFile) skippedCount += 1 $stderr.puts %<Read switch target "#{javaDestFile} present, therefore skipped"> else IO::write(javaDestFile, ERB.new(IO.read(File.join(File.dirname(__FILE__), '../../tmpl/readSwitch.erb')), $SAFE, '%<>').result(binding), mode: 'wb') end $stderr.puts %<Read Switch targets skipped: #{skippedCount}> if skippedCount > 0 end |