forked from activeadmin/activeadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuse_rails
executable file
·53 lines (43 loc) · 1.28 KB
/
use_rails
1
2
3
4
5
6
7
8
9
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env ruby
#
# Switches the development environment to use the given
# version of rails. Caches the Gemfile.locks so that
# switching it very fast.
#
require File.expand_path("../../spec/support/detect_rails_version", __FILE__)
def cmd(command)
puts command
exit 1 unless system command
end
version = ARGV[0]
unless version
puts "USAGE: ./script/#{__FILE__} VERSION [OPTIONS]"
puts
puts "Options:"
puts " --clobber Add this flag to remove the existing Gemfile.lock before running"
exit(1)
end
def file_or_symlink?(path)
File.exist?(path) || File.symlink?(path)
end
gem_lock_dir = ".gemfile-locks"
gem_lock_file = "#{gem_lock_dir}/Gemfile-#{version}.lock"
# Ensure our lock dir is created
cmd "mkdir #{gem_lock_dir}" unless File.exists?(gem_lock_dir)
# --clobber passed in
if File.exists?(gem_lock_file) && ARGV.include?('--clobber')
cmd "rm #{gem_lock_file}"
end
write_rails_version(version)
# Ensure that bundler installs
ENV['RUBYOPT'] = ''
if File.exists?(gem_lock_file)
cmd("rm Gemfile.lock") if file_or_symlink?("Gemfile.lock")
cmd("ln -s #{gem_lock_file} Gemfile.lock")
cmd("bundle")
else
cmd "rm Gemfile.lock" if file_or_symlink?("Gemfile.lock")
cmd "bundle install"
cmd "mv Gemfile.lock #{gem_lock_file}"
cmd("ln -s #{gem_lock_file} Gemfile.lock")
end