Module: SchemaDev::Gemfiles
Constant Summary collapse
- TEMPLATES_ROOT =
Pathname.new(__FILE__).dirname.parent.parent + "templates"
Instance Method Summary collapse
Instance Method Details
#_blow_away(relpath) ⇒ Object
50 51 52 53 |
# File 'lib/schema_dev/gemfiles.rb', line 50 def _blow_away(relpath) (@dst_root + relpath).rmtree rescue Errno::ENOENT end |
#_copy(relpath, filename) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/schema_dev/gemfiles.rb', line 41 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) end |
#build(config) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/schema_dev/gemfiles.rb', line 10 def build(config) Dir.mktmpdir do |tmpdir| @src_root = TEMPLATES_ROOT @dst_root = Pathname.new(tmpdir).realpath relpath = Pathname.new("gemfiles") abspath = @dst_root + relpath target_abspath = Pathname.new(".").realpath + relpath _copy(relpath, 'Gemfile.base') config.rails.each do |rails| rails_path = relpath + "rails-#{rails}" _copy(rails_path, 'Gemfile.base') config.db.each do |db| _copy(rails_path, "Gemfile.#{db}") end end if `diff -rq #{abspath} gemfiles 2>&1 | grep -v lock`.length == 0 return false end _blow_away(target_abspath) abspath.rename(target_abspath) return true end end |