This repository has been archived by the owner on Aug 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ruby.rb
126 lines (98 loc) · 2.46 KB
/
ruby.rb
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#
# Ruby via chruby
#
dep "default-ruby-env-2.2.0" do
requires "default-ruby-env".with(version: "2.2.0")
end
dep "default-ruby-env", :version do
requires "dotfiles",
"ruby-env".with(version: version),
"ruby-version".with(version: version),
"gems".with(version: version)
end
dep "ruby-env", :version do
version.ask("Which version of Ruby would you like to install?")
requires "ruby".with(version: version),
"gems".with(version: version)
end
GEMS = %w[bundler pry klipbook rubocop seeing_is_believing]
GEMS.each do |gem|
dep "#{gem}-gem", :version do
"gem".with(gem_name: gem, ruby_version: version)
end
end
dep "gems", :version do
requires "dotfiles", "ruby".with(version: version)
requires GEMS.map {|gem| "#{gem}-gem".with(version: version) }
end
dep "ruby-version", :version do
def file
"~/.ruby-version"
end
def contents
"#{version}\n"
end
met? { file.p.read == contents }
meet { file.p.write contents }
end
dep "rubies.dir" do
path "~/.rubies"
end
dep "ruby", :version do
requires "ruby-build up to date",
"chruby.managed",
"rubies.dir"
def base_path
"~/.rubies"
end
def build_path
base_path / version
end
met? {
build_path.p.exists?
}
meet {
shell "mkdir -p #{base_path}", :sudo => true
log_shell "Building via ruby-build", "/usr/local/bin/ruby-build #{version} #{build_path}"
}
end
dep "ruby-build.managed"
dep "ruby-build up to date" do
requires "ruby-build.managed"
before {
Babushka.host.pkg_helper.update_pkg_lists
}
meet {
shell("brew upgrade ruby-build")
}
end
# TODO Simplify this business if ww ensure we can source chruby before running it
dep "gem", :gem_name, :version, :ruby_version do
version.default!(:unset)
requires "chruby.managed"
def version?
version != :unset
end
def version_switch
if version?
"-v #{version}"
else
""
end
end
def version_test
if version?
/#{gem_name}\s+\([^(]*#{Regexp.escape version}/
else
/#{gem_name}/
end
end
met? {
log "Checking for gem #{gem_name} #{version_switch} under #{ruby_version}"
shell("chruby-exec #{ruby_version} -- gem list #{gem_name}") =~ version_test
}
meet {
log "Installing gem #{gem_name} #{version_switch} under #{ruby_version}"
log_shell "gem install #{gem_name} #{version_switch}", "chruby-exec #{ruby_version} -- gem install #{gem_name} #{version_switch}"
}
end