forked from rspec/rspec-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thorfile
53 lines (45 loc) · 1.24 KB
/
Thorfile
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
class Gemfile < Thor
desc "use VERSION", "installs the bundle using gemfiles/rails-VERSION"
def use(version)
"rm #{lockfile(version)}".tap do |m|
say m
system m
end
with(version, %w[bundle install --binstubs])
say `ln -s gemfiles/bin` unless File.exist?('bin')
`echo rails-#{version} > ./.gemfile`
end
desc "with VERSION COMMAND", "executes COMMAND with the gemfile for VERSION"
def with(version, *command)
gemfile(version).tap do |gemfile|
ENV["BUNDLE_GEMFILE"] = File.expand_path(gemfile)
say "BUNDLE_GEMFILE=#{gemfile}"
end
command.join(' ').tap do |m|
say m
system m
end
end
desc "which", "print out the configured gemfile"
def which
say `cat ./.gemfile`
end
desc "list", "list the available options for 'thor gemfile:use'"
def list
all = `ls gemfiles`.chomp.split.grep(/^rails/).reject {|i| i =~ /lock$/}
versions = all.grep(/^rails-\d\.\d/)
branches = all - versions
puts "releases:"
versions.sort.reverse.each {|i| puts i}
puts
puts "branches:"
branches.sort.reverse.each {|i| puts i}
end
private
def gemfile(version)
"gemfiles/rails-#{version}"
end
def lockfile(version)
gemfile(version) + ".lock"
end
end