Class: MetaCon::Loaders::RVM
Constant Summary
collapse
- RVMS =
"source $HOME/.rvm/scripts/rvm && "
Constants included
from CLIHelpers
CLIHelpers::ANSI, CLIHelpers::CONTEXT_OS, CLIHelpers::ESCS
Class Method Summary
collapse
-
.check_gemset_installed(ruby, gemset, opts) ⇒ Object
-
.check_installed(ruby, opts) ⇒ Object
-
.create_gemset(ruby, gemset, opts) ⇒ Object
-
.install(ruby, opts) ⇒ Object
-
.load_dependency(dependency_parts, state, proj, opts) ⇒ Object
-
.shc(cmdstr, v) ⇒ Object
-
.switch(ruby, gemset, opts) ⇒ Object
-
.switch_ruby(ruby, state, opts = {}) ⇒ Object
Methods included from CLIHelpers
#best_profile_file, #cfail, #chd, #check_tool, #color_puts, #command_exists?, #cstr2, #cwarn, #darwin?, #fj, #included, #linux?, #mac?, #result, #shellescape, #status
Methods included from Shorthand
#common_prefix, #included, #relative_path, #shcmd
Class Method Details
.check_gemset_installed(ruby, gemset, opts) ⇒ Object
49
50
51
52
|
# File 'lib/metacon/loaders/rvm.rb', line 49
def self.check_gemset_installed(ruby, gemset, opts)
o,e,s = shc("rvm use '#{ruby}'@'#{gemset}'", false)
return (s == 0 && e.strip.length == 0)
end
|
.check_installed(ruby, opts) ⇒ Object
44
45
46
47
|
# File 'lib/metacon/loaders/rvm.rb', line 44
def self.check_installed(ruby, opts)
o,e,s = shc("rvm use '#{ruby}@'", false)
return (s==0 && o =~ /using/i)
end
|
.create_gemset(ruby, gemset, opts) ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/metacon/loaders/rvm.rb', line 59
def self.create_gemset(ruby, gemset, opts)
o,e,s = shc("rvm use '#{ruby}' && rvm gemset create '#{gemset}'", opts[:verbose])
res = (o =~ /created/i) && (s == 0) && (e.strip.length == 0)
return res
end
|
.install(ruby, opts) ⇒ Object
54
55
56
57
|
# File 'lib/metacon/loaders/rvm.rb', line 54
def self.install(ruby, opts)
o,e,s = shc("rvm install #{ruby}", opts[:verbose])
return (s == 0 && check_installed(ruby,opts))
end
|
.load_dependency(dependency_parts, state, proj, opts) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/metacon/loaders/rvm.rb', line 6
def self.load_dependency(dependency_parts, state, proj, opts)
kind = dependency_parts.shift
if kind == 'ruby'
ruby = fix_ruby_version(dependency_parts)
return switch_ruby(ruby, state, opts)
elsif kind == 'gem'
else
raise "I don't handle #{kind} dependencies... am I missing something?"
end
end
|
.shc(cmdstr, v) ⇒ Object
22
|
# File 'lib/metacon/loaders/rvm.rb', line 22
def self.shc(cmdstr,v); return shcmd("#{RVMS} #{cmdstr}", v) end
|
.switch(ruby, gemset, opts) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/metacon/loaders/rvm.rb', line 68
def self.switch(ruby, gemset, opts)
o,e,s = shc("rvm '#{ruby}'@'#{gemset}' do rvm tools identifier", false)
identstr = o.strip
envsettings = "~/.rvm/environments/#{identstr}"
cmds = process_env_commands(IO.readlines(File.expand_path(envsettings)))
puts cmds.join("\n") if opts[:shell]
return true
end
|
.switch_ruby(ruby, state, opts = {}) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/metacon/loaders/rvm.rb', line 24
def self.switch_ruby(ruby, state, opts={})
unless check_installed(ruby,opts)
unless install(ruby,opts)
cfail "Failed to install ruby '#{ruby}'"
return false
end
end
gemset = fix_gemset_name(state)
unless check_gemset_installed(ruby, gemset, opts)
unless create_gemset(ruby, gemset, opts)
cfail "Failed to create a gemset '#{gemset}' for '#{ruby}'"
return false
end
end
return switch(ruby, gemset, opts)
end
|