cuken 0.1.4 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.relish +2 -0
- data/Gemfile +4 -4
- data/Gemfile.lock +17 -23
- data/VERSION +1 -1
- data/cuken.gems +108 -0
- data/cuken.gemspec +33 -10
- data/features/about.md +15 -2
- data/features/chef_examples/cookbooks_cookbook.feature +38 -3
- data/features/chef_examples/cookbooks_remote_repo.feature +10 -0
- data/features/chef_examples/cookbooks_repo.feature +5 -5
- data/features/{chef_steps → chef_examples}/knife_admin_client.feature +4 -4
- data/features/chef_examples/knife_client_create.feature +13 -0
- data/features/chef_steps/common_steps.feature +2 -2
- data/features/chef_steps/cookbook_steps.feature +12 -5
- data/features/chef_steps/node_steps.feature +1 -1
- data/features/file_steps/file_steps.feature +11 -11
- data/lib/cuken/all.rb +4 -0
- data/lib/cuken/api/chef/common.rb +46 -8
- data/lib/cuken/api/chef/knife.rb +107 -0
- data/lib/cuken/api/chef.rb +21 -13
- data/lib/cuken/api/common.rb +12 -0
- data/lib/cuken/api/rvm.rb +501 -0
- data/lib/cuken/api/ssh-forever.rb +237 -0
- data/lib/cuken/chef.rb +2 -0
- data/lib/cuken/common.rb +1 -0
- data/lib/cuken/cucumber/chef/common.rb +4 -2
- data/lib/cuken/cucumber/chef/cookbook.rb +87 -12
- data/lib/cuken/cucumber/chef/data_bag.rb +27 -0
- data/lib/cuken/cucumber/chef/knife.rb +10 -0
- data/lib/cuken/cucumber/chef/node.rb +20 -8
- data/lib/cuken/cucumber/chef/role.rb +18 -1
- data/lib/cuken/cucumber/chef.rb +5 -3
- data/lib/cuken/cucumber/cmd.rb +1 -1
- data/lib/cuken/cucumber/file.rb +18 -2
- data/lib/cuken/cucumber/rvm.rb +4 -0
- data/lib/cuken/rvm.rb +3 -0
- data/spec/api/knife_spec.rb +94 -0
- data/spec/api/rvm_spec.rb +274 -0
- data/spec/api/rvmrc_processor_spec.rb +288 -0
- data/spec/spec_helper.rb +58 -2
- metadata +67 -30
@@ -0,0 +1,501 @@
|
|
1
|
+
module ::Cuken
|
2
|
+
module Api
|
3
|
+
module Rvm
|
4
|
+
|
5
|
+
class RvmrcProcessor
|
6
|
+
|
7
|
+
attr_writer :gemspecs_to_install
|
8
|
+
|
9
|
+
def initialize(path)
|
10
|
+
@root_path = ::File.directory?(path) ? path : File.dirname(path)
|
11
|
+
rvmrc_read(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
# read the .rvmrc file contents into @rvmrc
|
15
|
+
def rvmrc_read(path)
|
16
|
+
fn = ::File.directory?(path) ? path + '/.rvmrc' : path
|
17
|
+
@rvmrc = ::File.new(fn).read
|
18
|
+
return true if @rvmrc.size > 0
|
19
|
+
end
|
20
|
+
|
21
|
+
# return the .rvmrc file contents
|
22
|
+
def rvmrc
|
23
|
+
@rvmrc
|
24
|
+
end
|
25
|
+
|
26
|
+
# return ruby name parsed from .rvmrc file contents
|
27
|
+
def rvmrc_ruby_name
|
28
|
+
extract_rubie(rvmrc)
|
29
|
+
end
|
30
|
+
|
31
|
+
# return gemset name parsed from .rvmrc file contents
|
32
|
+
def rvmrc_gemset_name
|
33
|
+
extract_gemset(rvmrc)
|
34
|
+
end
|
35
|
+
|
36
|
+
# return concatenated string of rvmrc_ruby@rvmrc_gemset
|
37
|
+
def rvmrc_ruby_gemset(rvmrc)
|
38
|
+
"#{extract_rubie(rvmrc)}@#{extract_gemset(rvmrc)}"
|
39
|
+
end
|
40
|
+
|
41
|
+
# return an array of .rvmrc file paths found beneath a root folder
|
42
|
+
def find_rvmrc_files(rvmrc_root)
|
43
|
+
Dir.glob(rvmrc_root + '/**' + '/.rvmrc')
|
44
|
+
end
|
45
|
+
|
46
|
+
# return an arry of paths containing .rvmrc files
|
47
|
+
def find_rvmrc_paths(rvmrc_root)
|
48
|
+
root = File.directory?(rvmrc_root) ? rvmrc_root : File.dirname(rvmrc_root)
|
49
|
+
dirs = []
|
50
|
+
find_rvmrc_files(root).each do |path|
|
51
|
+
dirs << File.dirname(File.expand_path(path)) if File.file?(path)
|
52
|
+
end
|
53
|
+
dirs
|
54
|
+
end
|
55
|
+
|
56
|
+
#return an array of *.gems file paths found beneath a root folder
|
57
|
+
def find_gems_files(rvmrc_root)
|
58
|
+
Dir.glob(rvmrc_root + '/**' + '/*.gems')
|
59
|
+
end
|
60
|
+
|
61
|
+
# returns rubies and gemsets from .rvmrc files glob'ed below
|
62
|
+
# a root folder.
|
63
|
+
def all_rubies_gemsets(root_path=@root_path)
|
64
|
+
@all_rubies_gemsets = Hash.new([])
|
65
|
+
arry=find_rvmrc_paths(root_path)
|
66
|
+
arry.each do |dir|
|
67
|
+
Dir.glob(dir + '/*.gems').each do |fn|
|
68
|
+
gsn = File.basename(fn,'.gems').to_s
|
69
|
+
rvmrc_read(dir + '/.rvmrc')
|
70
|
+
rube = rvmrc_ruby_name
|
71
|
+
egsn = rvmrc_gemset_name
|
72
|
+
@all_rubies_gemsets[rube] = [] unless @all_rubies_gemsets.key? rube
|
73
|
+
if gsn == egsn
|
74
|
+
@all_rubies_gemsets[rube] << {:ruby_alias => "cuken_#{rube}",:gemset_alias => "cuken_#{gsn}", :gemset_name => gsn, :gemset_path => fn}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
@all_rubies_gemsets
|
79
|
+
end
|
80
|
+
|
81
|
+
# returns hash of all gemsets, per-Ruby, in all .rvmrc files beneath a root folder
|
82
|
+
def all_gemsets(root_path=@root_path)
|
83
|
+
default = Hash.new{|hsh,ky| hsh[ky] = {:ruby_alias => "cuken_#{ky}"}}
|
84
|
+
@all_rubies_gemsets ||= all_rubies_gemsets(root_path)
|
85
|
+
@all_gemsets = @all_rubies_gemsets.inject(default){|h,(k,v)| h[k]; h[k][:gemsets]=v; h }
|
86
|
+
end
|
87
|
+
|
88
|
+
# returns array of all rubies in all .rvmrc files beneath a root folder
|
89
|
+
def all_rubies(root_path=@root_path)
|
90
|
+
@all_rubies_gemsets ||= all_rubies_gemsets(root_path)
|
91
|
+
@all_rubies = @all_rubies_gemsets.keys
|
92
|
+
end
|
93
|
+
|
94
|
+
# yield a block in the environment of each in the installed rubies,
|
95
|
+
# and return current Ruby string even if the given block raises
|
96
|
+
def each_ruby
|
97
|
+
begin
|
98
|
+
all_rubies(@root_path).each do |rubie|
|
99
|
+
RVM.use(rubie)
|
100
|
+
yield rubie
|
101
|
+
end
|
102
|
+
rescue
|
103
|
+
ensure
|
104
|
+
RVM.reset_current!
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# create gemsets parsed from all .rvmrc files beneath a root folder
|
109
|
+
def create_gemsets
|
110
|
+
each_ruby do |rubie|
|
111
|
+
all_gemsets(@root_path)[rubie][:gemsets].each do |hsh|
|
112
|
+
::RVM.gemset.create([hsh[:gemset_name]])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# Return array of [gem_name, gem_version] to be installed into all
|
118
|
+
# gemsets found in .rvmrc files. Default is Bundler versio 1.0.10
|
119
|
+
def gemspecs_to_install
|
120
|
+
@gemspecs_to_install ||= [['bundler', '1.0.10']]
|
121
|
+
end
|
122
|
+
|
123
|
+
# Install @gemspecs_to_install contents using rubies and gemsets
|
124
|
+
# found in .rvmrc files.
|
125
|
+
def gems_install
|
126
|
+
create_gemsets
|
127
|
+
each_ruby do |rubie|
|
128
|
+
gemspecs_to_install.each { |spec| install_gem(rubie, spec) }
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# return the options string for Ruby's `gem install...` CLI
|
133
|
+
def gem_install_options
|
134
|
+
@gem_install_options ||= ['no_ri', 'no_rdoc']
|
135
|
+
"--" + @gem_install_options.join(' --')
|
136
|
+
end
|
137
|
+
|
138
|
+
# install given gem into all ruby+gemsets parsed from .rvmrc files beneath a root folder
|
139
|
+
def install_gem(rubie, spec)
|
140
|
+
gem, version = spec
|
141
|
+
all_gemsets.each do |rubie, hsh|
|
142
|
+
hsh[:gemsets].each do |h|
|
143
|
+
if gem_available?(spec)
|
144
|
+
puts "info: Gem #{gem}-#{version} already installed in #{rvm_current_name}."
|
145
|
+
else
|
146
|
+
puts "info: Installing gem #{gem}-#{version} in #{rvm_current_name}..."
|
147
|
+
RVM.gemset.use(h[:gemset_alias])
|
148
|
+
RVM.run("rvm --create use #{h[:gemset_alias]}; gem install #{gem} -v#{version} #{gem_install_options}")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# return the parsed .rvmrc info for the current ruby
|
155
|
+
def current_ruby_info(rubie)
|
156
|
+
@all_rubies_gemsets ||= all_rubies_gemsets
|
157
|
+
@all_rubies_gemsets[rubie]
|
158
|
+
end
|
159
|
+
|
160
|
+
def rvm_path
|
161
|
+
pn = Pathname.new(File.expand_path(ENV['rvm_path'] || '~/.rvm'))
|
162
|
+
pn.exist? ? pn : raise(RuntimeError, "Could not find RVM's .rvm folder (#{pn})", caller)
|
163
|
+
end
|
164
|
+
# Does not install existing RVM rubies that are listed in the .rvmrc files
|
165
|
+
# raise an error if RVM's install root does not exist
|
166
|
+
def setup_rubies
|
167
|
+
rvm_loaded? ? true : raise(RuntimeError, "RVM library not loaded.", caller)
|
168
|
+
@all_rubies_gemsets ||= all_rubies_gemsets(@root_path)
|
169
|
+
@all_rubies_gemsets.keys.each do |rubie|
|
170
|
+
if RVM.list_strings.include?(rubie)
|
171
|
+
puts "info: Rubie #{rubie} already installed."
|
172
|
+
else
|
173
|
+
with_rvm_environment_vars do
|
174
|
+
install_rubie(rubie)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
RVM.alias_create(current_ruby_info(rubie)[0][:ruby_alias], "#{rubie}") unless rubie == current_ruby_info(rubie)[0][:ruby_alias]
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
private
|
182
|
+
def extract_rubie(rvmrc)
|
183
|
+
rvmrc[/ruby_id=\"(.*)\"/, 1]
|
184
|
+
end
|
185
|
+
def extract_gemset(rvmrc)
|
186
|
+
rvmrc[/gemset_id=\"(.*)\"/, 1]
|
187
|
+
end
|
188
|
+
def gem_available?(spec)
|
189
|
+
gem, version = spec
|
190
|
+
RVM.ruby_eval("require 'rubygems' ; print Gem.available?('#{gem}','#{version}')").stdout == 'true'
|
191
|
+
end
|
192
|
+
def rvm_current_name
|
193
|
+
RVM.current.expanded_name
|
194
|
+
end
|
195
|
+
|
196
|
+
def rvm_loaded?
|
197
|
+
@rvm_setup = defined?(RVM) ? true : false
|
198
|
+
return(true) if @rvm_setup
|
199
|
+
rvm_lib_path = rvm_path + "lib" rescue return
|
200
|
+
$LOAD_PATH.unshift(rvm_lib_path.to_s) unless $LOAD_PATH.include?(rvm_lib_path.to_s)
|
201
|
+
require 'rvm'
|
202
|
+
@rvm_setup = defined?(RVM) ? true : false
|
203
|
+
end
|
204
|
+
|
205
|
+
def install_rubie(rubie)
|
206
|
+
std_msg = "info: Rubie #{rubie} installed."
|
207
|
+
err_msg = "Failed #{rubie} install! Check RVM logs here: #{RVM.path}/log/#{rubie}"
|
208
|
+
puts "info: Rubie #{rubie} installation inprogress. This couldtake awhile..."
|
209
|
+
RVM.install(rubie, rvm_install_options) ? puts(std_msg) : abort(err_msg)
|
210
|
+
end
|
211
|
+
|
212
|
+
def rvm_install_options
|
213
|
+
{ }
|
214
|
+
end
|
215
|
+
|
216
|
+
def with_rvm_environment_vars
|
217
|
+
my_vars = rvm_environment_vars
|
218
|
+
current_vars = my_vars.inject({}) { |cvars,kv| k,v = kv ; cvars[k]= ENV[k] ; cvars }
|
219
|
+
set_environment_vars(my_vars)
|
220
|
+
yield
|
221
|
+
ensure
|
222
|
+
set_environment_vars(current_vars)
|
223
|
+
end
|
224
|
+
|
225
|
+
def set_environment_vars(vars)
|
226
|
+
vars.each { |k,v| ENV[k] = v }
|
227
|
+
end
|
228
|
+
|
229
|
+
def rvm_environment_vars
|
230
|
+
if rvm_for_macports?
|
231
|
+
{'CC' => '/usr/bin/gcc-4.2',
|
232
|
+
'CFLAGS' => '-O2 -arch x86_64',
|
233
|
+
'LDFLAGS' => '-L/opt/local/lib -arch x86_64',
|
234
|
+
'CPPFLAGS' => '-I/opt/local/include'}
|
235
|
+
else
|
236
|
+
{}
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def rvm_for_macports?
|
241
|
+
`uname`.strip == 'Darwin' && `which port`.present?
|
242
|
+
end
|
243
|
+
|
244
|
+
end # class RvmrcProcessor
|
245
|
+
|
246
|
+
module_function
|
247
|
+
class << self
|
248
|
+
attr_accessor :rvm_install_rubies, :rvm_install_gem_specs,
|
249
|
+
:rvm_gem_install_options
|
250
|
+
end
|
251
|
+
|
252
|
+
def rvmrc(path)
|
253
|
+
@rvmrc ||= RvmrcProcessor.new(path)
|
254
|
+
end
|
255
|
+
|
256
|
+
def rvm_current_name
|
257
|
+
RVM.current.expanded_name
|
258
|
+
end
|
259
|
+
|
260
|
+
def rvm_gem_install_options
|
261
|
+
@rvm_gem_install_options ||= ['no_ri', 'no_rdoc']
|
262
|
+
"--" + @rvm_gem_install_options.join(' --')
|
263
|
+
end
|
264
|
+
|
265
|
+
def rvm_install_rubies
|
266
|
+
@rvm_install_rubies ||= []
|
267
|
+
end
|
268
|
+
|
269
|
+
def rvm_install_gemspecs
|
270
|
+
@rvm_install_gemspecs ||= [['bundler', '1.0.10']]
|
271
|
+
end
|
272
|
+
|
273
|
+
def rvm_create_gemsets
|
274
|
+
@rvm_create_gemsets ||= []
|
275
|
+
end
|
276
|
+
|
277
|
+
def rvm_requested_gemset(gemset)
|
278
|
+
@rvm_requested_gemset = gemset
|
279
|
+
end
|
280
|
+
|
281
|
+
def rvm_requested_gemset
|
282
|
+
@rvm_requested_gemset ||='vagrant'
|
283
|
+
end
|
284
|
+
#wip
|
285
|
+
def rvm_path
|
286
|
+
pn = Pathname.new(File.expand_path(ENV['rvm_path'] || '~/.rvm'))
|
287
|
+
pn.exist? ? pn : raise(RuntimeError, "Could not find RVM's .rvm folder (#{pn})", caller)
|
288
|
+
end
|
289
|
+
|
290
|
+
def rvm_local_install?
|
291
|
+
rvm_path.dirname.realpath.directory?
|
292
|
+
end
|
293
|
+
# done
|
294
|
+
def rvm_loaded?
|
295
|
+
_rvm_load
|
296
|
+
end
|
297
|
+
|
298
|
+
def rvm_gemset_paths(root_path='/usr/src/cuken')
|
299
|
+
rpn = Pathname(root_path)
|
300
|
+
rvmrc_dirs = []
|
301
|
+
Dir.glob((rpn + '**' + '.rvmrc').to_s).each do |d|
|
302
|
+
dn = File.dirname(d)
|
303
|
+
rvmrc_dirs << dn if File.directory?(dn)
|
304
|
+
end
|
305
|
+
rvmrc_dirs
|
306
|
+
end
|
307
|
+
|
308
|
+
# done
|
309
|
+
def rvmrc_rubies_gemsets(root_path='/usr/src/cuken')
|
310
|
+
@rvmrc_rubies_gemsets = Hash.new([])
|
311
|
+
arry=rvm_gemset_paths(root_path)
|
312
|
+
arry.each do |dir|
|
313
|
+
Dir.glob(dir + '/*.gems').each do |fn|
|
314
|
+
gsn = File.basename(fn,'.gems').to_s
|
315
|
+
rvmrc = File.new(File.dirname(fn) + '/.rvmrc').read
|
316
|
+
rube = rvmrc_extract_ruby(rvmrc)
|
317
|
+
egsn = rvmrc_extract_gemset(rvmrc)
|
318
|
+
@rvmrc_rubies_gemsets[rube] = [] unless @rvmrc_rubies_gemsets.key? rube
|
319
|
+
@rvmrc_rubies_gemsets[rube] << gsn if gsn == egsn
|
320
|
+
end
|
321
|
+
end
|
322
|
+
@rvmrc_rubies_gemsets
|
323
|
+
end
|
324
|
+
# done
|
325
|
+
def rvmrc_rubies
|
326
|
+
@rvmrc_rubies ||= _rvmrc_rubies #.keys.map{ |rubie| "#{rubie}@#{rvm_requested_gemset}" }
|
327
|
+
end
|
328
|
+
#wip
|
329
|
+
def rvm_rubies_setup(root_path='/usr/src/cuken')
|
330
|
+
rvm_loaded? ? true : raise(RuntimeError, "RVM library not loaded.", caller)
|
331
|
+
@rvmrc_rubies_gemsets ? true : rvmrc_rubies_gemsets(root_path)
|
332
|
+
@rvmrc_rubies_gemsets.keys.each do |rubie|
|
333
|
+
if RVM.list_strings.include?(rubie)
|
334
|
+
puts "info: Rubie #{rubie} already installed."
|
335
|
+
else
|
336
|
+
with_rvm_environment_vars do
|
337
|
+
_rvm_install_rubie(rubie)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
RVM.alias_create(rvmrc_rubies[rubie][:alias], "#{rubie}@#{rvm_requested_gemset}") unless rubie == rvmrc_rubies[rubie][:alias]
|
341
|
+
end
|
342
|
+
end
|
343
|
+
#done
|
344
|
+
def rvm_current_rubie_info
|
345
|
+
rvmrc_rubies[_rvm_current_rubie_name]
|
346
|
+
end
|
347
|
+
|
348
|
+
# Install @rvm_install_gemspecs gemspec using rubies and gemsets
|
349
|
+
# found in .rvmrc files.
|
350
|
+
# done
|
351
|
+
def rvmrc_gems_install(root_path)
|
352
|
+
@rvmrc_root_path = root_path
|
353
|
+
_rvmrc_create_gemsets
|
354
|
+
_each_rvmrc_rubie do |rubie|
|
355
|
+
rvm_install_gemspecs.each { |spec| _rvmrc_install_gem(rubie, spec) }
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
def rvmrc_gemsets_install(root_path)
|
360
|
+
@rvmrc_root_path = root_path
|
361
|
+
_each_rvmrc_rubie do |rubie|
|
362
|
+
rvm_install_gemspecs.each { |spec| _rvmrc_install_gem(rubie, spec) }
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
protected
|
367
|
+
#done
|
368
|
+
def _rvm_load
|
369
|
+
@rvm_setup = false
|
370
|
+
rvm_lib_path = rvm_path + "lib" rescue return
|
371
|
+
$LOAD_PATH.unshift(rvm_lib_path.to_s) unless $LOAD_PATH.include?(rvm_lib_path.to_s)
|
372
|
+
require 'rvm'
|
373
|
+
@rvm_setup = defined?(RVM) ? true : false
|
374
|
+
end
|
375
|
+
module_function :_rvm_load
|
376
|
+
#done
|
377
|
+
def _rvm_install_rubie(rubie)
|
378
|
+
std_msg = "info: Rubie #{rubie} installed."
|
379
|
+
err_msg = "Failed #{rubie} install! Check RVM logs here: #{RVM.path}/log/#{rubie}"
|
380
|
+
puts "info: Rubie #{rubie} installation inprogress. This couldtake awhile..."
|
381
|
+
RVM.install(rubie, rvm_install_options) ? puts(std_msg) : abort(err_msg)
|
382
|
+
end
|
383
|
+
module_function :_rvm_install_rubie
|
384
|
+
|
385
|
+
#done
|
386
|
+
def rvmrc_extract_ruby_gemset(rvmrc)
|
387
|
+
"#{rvmrc_extract_ruby(rvmrc)}@#{rvmrc_extract_gemset(rvmrc)}"
|
388
|
+
end
|
389
|
+
module_function :rvmrc_extract_ruby_gemset
|
390
|
+
#done
|
391
|
+
def rvmrc_extract_ruby(rvmrc)
|
392
|
+
rvmrc[/ruby_id=\"(.*)\"/, 1]
|
393
|
+
end
|
394
|
+
module_function :rvmrc_extract_ruby
|
395
|
+
#done
|
396
|
+
def rvmrc_extract_gemset(rvmrc)
|
397
|
+
rvmrc[/gemset_id=\"(.*)\"/, 1]
|
398
|
+
end
|
399
|
+
module_function :rvmrc_extract_gemset
|
400
|
+
#done
|
401
|
+
def _rvmrc_rubies
|
402
|
+
default = Hash.new{|hsh,ky| hsh[ky] = {:alias => "cuken-#{ky}"}}
|
403
|
+
@rvmrc_rubies_gemsets ||= rvmrc_rubies_gemsets(@rvmrc_root_path)
|
404
|
+
@rvmrc_rubies = @rvmrc_rubies_gemsets.keys.inject(default){|h,(k,v)| h[k]; h }
|
405
|
+
end
|
406
|
+
module_function :_rvmrc_rubies
|
407
|
+
#done
|
408
|
+
def _rvmrc_gemsets
|
409
|
+
default = Hash.new{|hsh,ky| hsh[ky] = {:alias => "cuken-#{ky}"}}
|
410
|
+
@rvmrc_rubies_gemsets ||= rvmrc_rubies_gemsets(@rvmrc_root_path)
|
411
|
+
@rvmrc_gemsets = @rvmrc_rubies_gemsets.inject(default){|h,(k,v)| h[k]; h[k][:gemsets]=v; h }
|
412
|
+
end
|
413
|
+
module_function :_rvmrc_gemsets
|
414
|
+
# done
|
415
|
+
def _each_rvmrc_rubie
|
416
|
+
_rvmrc_rubies.each do |ary|
|
417
|
+
RVM.use(ary[0])
|
418
|
+
yield ary[0]
|
419
|
+
end
|
420
|
+
ensure
|
421
|
+
RVM.reset_current!
|
422
|
+
end
|
423
|
+
module_function :_each_rvmrc_rubie
|
424
|
+
# done
|
425
|
+
def _rvmrc_create_gemsets
|
426
|
+
_rvmrc_gemsets.each do |hsh|
|
427
|
+
RVM.use hsh[0]
|
428
|
+
hsh[1][:gemsets].each do |gmst|
|
429
|
+
# TODO: Post refactor
|
430
|
+
#RVM.gemset.create([gmst])
|
431
|
+
end
|
432
|
+
end
|
433
|
+
end
|
434
|
+
module_function :_rvmrc_create_gemsets
|
435
|
+
#done
|
436
|
+
def _rvmrc_install_gem(rubie, spec)
|
437
|
+
gem, version = spec
|
438
|
+
_rvmrc_gemsets.each do |hsh|
|
439
|
+
rubie = hsh[0]
|
440
|
+
hsh[1][:gemsets].each do |gmst|
|
441
|
+
#RVM.gemset.create([gmst])
|
442
|
+
RVM.gemset.use(gmst)
|
443
|
+
if _rvm_gem_available?(spec)
|
444
|
+
puts "info: Gem #{gem}-#{version} already installed in #{rvm_current_name}."
|
445
|
+
else
|
446
|
+
puts "info: Installing gem #{gem}-#{version} in #{rvm_current_name}..."
|
447
|
+
RVM.run("rvm --create use #{rubie}@#{gmst}; gem install #{gem} -v#{version} #{rvm_gem_install_options}")
|
448
|
+
end
|
449
|
+
end
|
450
|
+
end
|
451
|
+
end
|
452
|
+
module_function :_rvmrc_install_gem
|
453
|
+
|
454
|
+
# done
|
455
|
+
def set_environment_vars(vars)
|
456
|
+
vars.each { |k,v| ENV[k] = v }
|
457
|
+
end
|
458
|
+
module_function :set_environment_vars
|
459
|
+
#done
|
460
|
+
def with_rvm_environment_vars
|
461
|
+
my_vars = rvm_environment_vars
|
462
|
+
puts my_vars
|
463
|
+
current_vars = my_vars.inject({}) { |cvars,kv| k,v = kv ; cvars[k]= ENV[k] ; cvars }
|
464
|
+
puts current_vars
|
465
|
+
set_environment_vars(my_vars)
|
466
|
+
yield
|
467
|
+
ensure
|
468
|
+
set_environment_vars(current_vars)
|
469
|
+
end
|
470
|
+
module_function :with_rvm_environment_vars
|
471
|
+
#done
|
472
|
+
def rvm_environment_vars
|
473
|
+
if rvm_for_macports?
|
474
|
+
{'CC' => '/usr/bin/gcc-4.2',
|
475
|
+
'CFLAGS' => '-O2 -arch x86_64',
|
476
|
+
'LDFLAGS' => '-L/opt/local/lib -arch x86_64',
|
477
|
+
'CPPFLAGS' => '-I/opt/local/include'}
|
478
|
+
else
|
479
|
+
{}
|
480
|
+
end
|
481
|
+
end
|
482
|
+
module_function :rvm_environment_vars
|
483
|
+
#done
|
484
|
+
def rvm_for_macports?
|
485
|
+
`uname`.strip == 'Darwin' && `which port`.present?
|
486
|
+
end
|
487
|
+
module_function :rvm_for_macports?
|
488
|
+
# done
|
489
|
+
def rvm_install_options
|
490
|
+
{ }
|
491
|
+
end
|
492
|
+
module_function :rvm_install_options
|
493
|
+
#done
|
494
|
+
def _rvm_gem_available?(spec)
|
495
|
+
gem, version = spec
|
496
|
+
RVM.ruby_eval("require 'rubygems' ; print Gem.available?('#{gem}','#{version}')").stdout == 'true'
|
497
|
+
end
|
498
|
+
module_function :_rvm_gem_available?
|
499
|
+
end
|
500
|
+
end
|
501
|
+
end
|