-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_install_gemset
executable file
·78 lines (55 loc) · 1.78 KB
/
create_install_gemset
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env ruby
##########################################
###
## File: create_install_getset
## Desc: Builds an executable file to reinstall the gemset taken
## into account the different gem dependencies.
##
## NOTE: Using shell script with 'rvm gemset create/use' and
## 'gem install' rather than creating a Gemfile and using
## bundler because in my environment I keep at least one
## gemset that has several hundred gems which I have declared
## worthy to use. Bundler just can't handle that large a
## number.
#
require 'pathname'
require 'date'
$gem_hash = Hash.new
$gem_names= Array.new
Gem::Specification.all.each do |gs|
# ignore duplicates - they are just different versions of the same thing
$gem_names << gs.name unless $gem_names.include?(gs.name)
$gem_hash[gs.name] = gs
end
def do_it
$gem_names.each do |g|
next if g.nil?
gd = $gem_hash[g].dependencies.map {|d| d.name}
gd.each do |gg|
x = $gem_names.index(gg)
$gem_names[x] = nil unless x.nil?
end unless gd.empty?
end
$gem_names.compact!
end # of def do_it
do_it
temp_str = `rvm current`
gemset_name = temp_str.include?('@') ? temp_str.chomp.split('@').last : 'default'
outfile_path= Pathname.pwd + "install_gemset_#{gemset_name}.s"
OUTFILE = outfile_path.open('w')
header = <<EOS
###################################################################
###
## File: #{outfile_path.basename}
## Desc: Minimum set of gem installs to reinstall entire gemset
## taking into account the gem dependencies.
##
## Created #{DateTime.now}
#
rvm gemset use #{gemset_name} #{'default' == gemset_name ? '' : '--create'}
EOS
OUTFILE.puts header
$gem_names.each_slice(10) do |g|
OUTFILE.puts "gem install #{g.join(' ')}"
end
OUTFILE.close