Module: SchemaDev::Gemfiles

Extended by:
Gemfiles
Included in:
Gemfiles
Defined in:
lib/schema_dev/gemfiles.rb

Instance Method Summary collapse

Instance Method Details

#_force_rename(src, dst) ⇒ Object



41
42
43
44
# File 'lib/schema_dev/gemfiles.rb', line 41

def _force_rename(src, dst)
  dst.rmtree if dst.directory?
  src.rename dst
end

#_install(relpath) ⇒ Object



37
38
39
# File 'lib/schema_dev/gemfiles.rb', line 37

def _install(relpath)
  Templates.install_relative src: relpath, dst: @tmpdir
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
# File 'lib/schema_dev/gemfiles.rb', line 10

def build(config)
  Dir.mktmpdir do |tmpdir|
    @tmpdir = Pathname.new(tmpdir).realpath

    gemfiles = Pathname("gemfiles")
    tmp_root = @tmpdir + gemfiles
    target_root = Pathname.new(".").realpath + gemfiles

    _install gemfiles + 'Gemfile.base'

    config.activerecord.each do |activerecord|
      activerecord_path = gemfiles + "activerecord-#{activerecord}"
      _install activerecord_path + 'Gemfile.base'
      config.db.each do |db|
        _install  activerecord_path + "Gemfile.#{db}"
      end
    end

    if `diff -rq #{tmp_root} #{target_root} 2>&1 | grep -v lock`.length == 0
      return false
    end

    _force_rename(tmp_root, target_root)
    return true
  end
end