lib/schema_dev/gemfiles.rb in schema_dev-3.5.1 vs lib/schema_dev/gemfiles.rb in schema_dev-3.6.0

- old
+ new

@@ -7,49 +7,40 @@ module Gemfiles extend self def build(config) Dir.mktmpdir do |tmpdir| - @src_root = Templates.root - @dst_root = Pathname.new(tmpdir).realpath + @tmpdir = Pathname.new(tmpdir).realpath - relpath = Pathname.new("gemfiles") - abspath = @dst_root + relpath - target_abspath = Pathname.new(".").realpath + relpath + gemfiles = Pathname("gemfiles") + tmp_root = @tmpdir + gemfiles + target_root = Pathname.new(".").realpath + gemfiles - _copy(relpath, 'Gemfile.base') + _install gemfiles + 'Gemfile.base' config.activerecord.each do |activerecord| - - activerecord_path = relpath + "activerecord-#{activerecord}" - _copy(activerecord_path, 'Gemfile.base') - + activerecord_path = gemfiles + "activerecord-#{activerecord}" + _install activerecord_path + 'Gemfile.base' config.db.each do |db| - _copy(activerecord_path, "Gemfile.#{db}") + _install activerecord_path + "Gemfile.#{db}" end end - if `diff -rq #{abspath} gemfiles 2>&1 | grep -v lock`.length == 0 + if `diff -rq #{tmp_root} #{target_root} 2>&1 | grep -v lock`.length == 0 return false end - _blow_away(target_abspath) - abspath.rename(target_abspath) + _force_rename(tmp_root, target_root) return true end end - def _copy(relpath, filename) - srcfile = @src_root + relpath + filename - dstfile = @dst_root + relpath + filename - return unless srcfile.exist? - - dstfile.dirname.mkpath - FileUtils.copy_file(srcfile, dstfile) + def _install(relpath) + Templates.install_relative src: relpath, dst: @tmpdir end - def _blow_away(relpath) - (@dst_root + relpath).rmtree - rescue Errno::ENOENT + def _force_rename(src, dst) + dst.rmtree if dst.directory? + src.rename dst end end end