Module: Cuken::Api::Rvm
- Extended by:
- RVM
- Includes:
- Aruba::Api, Common
- Defined in:
- lib/cuken/api/rvm.rb,
lib/cuken/api/rvm/wip.rb,
lib/cuken/api/rvm/common.rb,
lib/cuken/api/rvm/gemsets.rb
Defined Under Namespace
Modules: Common, Gemsets Classes: RvmHelper, RvmrcProcessor
Constant Summary
Constants included from Aruba::Api
Aruba::Api::DEFAULT_IO_WAIT_SECONDS, Aruba::Api::DEFAULT_TIMEOUT_SECONDS
Class Attribute Summary collapse
-
.rvm_gem_install_options ⇒ Object
Returns the value of attribute rvm_gem_install_options.
-
.rvm_install_gem_specs ⇒ Object
Returns the value of attribute rvm_install_gem_specs.
-
.rvm_install_rubies ⇒ Object
Returns the value of attribute rvm_install_rubies.
Class Method Summary collapse
-
._each_rvmrc_rubie ⇒ Object
done.
-
._rvm_gem_available?(spec) ⇒ Object
done.
-
._rvm_install_rubie(rubie) ⇒ Object
done.
-
._rvm_load ⇒ Object
done.
-
._rvmrc_create_gemsets ⇒ Object
done.
-
._rvmrc_gemsets ⇒ Object
done.
-
._rvmrc_install_gem(rubie, spec) ⇒ Object
done.
-
._rvmrc_rubies ⇒ Object
done.
- .run_simple_gemset(cmd_str, options = {}) ⇒ Object
- .rvm_create_gemsets ⇒ Object
- .rvm_current_name ⇒ Object
-
.rvm_current_rubie_info ⇒ Object
done.
-
.rvm_environment_vars ⇒ Object
done.
-
.rvm_for_macports? ⇒ Object
done.
- .rvm_gemset_paths(root_path = '/usr/src/cuken') ⇒ Object
- .rvm_install_gemspecs ⇒ Object
-
.rvm_install_options ⇒ Object
done.
-
.rvm_loaded? ⇒ Boolean
done.
- .rvm_local_install? ⇒ Boolean
-
.rvm_path ⇒ Object
wip.
- .rvm_requested_gemset ⇒ Object
-
.rvm_rubies_setup(root_path = '/usr/src/cuken') ⇒ Object
wip.
- .rvmrc(path) ⇒ Object
-
.rvmrc_extract_gemset(rvmrc) ⇒ Object
done.
-
.rvmrc_extract_ruby(rvmrc) ⇒ Object
done.
-
.rvmrc_extract_ruby_gemset(rvmrc) ⇒ Object
done.
-
.rvmrc_gems_install(root_path) ⇒ Object
Install @rvm_install_gemspecs gemspec using rubies and gemsets found in .rvmrc files.
- .rvmrc_gemsets_install(root_path) ⇒ Object
-
.rvmrc_rubies ⇒ Object
done.
-
.rvmrc_rubies_gemsets(root_path = '/usr/src/cuken') ⇒ Object
done.
-
.set_environment_vars(vars) ⇒ Object
done.
-
.with_rvm_environment_vars ⇒ Object
done.
Instance Method Summary collapse
Methods included from Aruba::Api
#_create_file, #_ensure_newline, #_mkdir, #_write_interactive, #all_output, #all_stderr, #all_stdout, #announce_or_puts, #append_to_file, #assert_exact_output, #assert_exit_status_and_output, #assert_exit_status_and_partial_output, #assert_exiting_with, #assert_failing_with, #assert_partial_output, #assert_passing_with, #cd, #check_directory_presence, #check_exact_file_content, #check_file_content, #check_file_presence, #create_dir, #current_dir, #current_ruby, #detect_ruby, #dirs, #exit_timeout, #get_process, #in_dir, #io_wait, #only_processes, #original_env, #output_from, #overwrite_file, #prep_for_fs_check, #processes, #regexp, #register_process, #remove_file, #restore_env, #run, #run_interactive, #run_simple, #set_env, #stderr_from, #stdout_from, #stop_processes!, #type, #unescape, #unset_bundler_env_vars, #use_clean_gemset, #write_file
Class Attribute Details
.rvm_gem_install_options ⇒ Object
Returns the value of attribute rvm_gem_install_options.
251 252 253 |
# File 'lib/cuken/api/rvm/wip.rb', line 251 def @rvm_gem_install_options end |
.rvm_install_gem_specs ⇒ Object
Returns the value of attribute rvm_install_gem_specs.
251 252 253 |
# File 'lib/cuken/api/rvm/wip.rb', line 251 def rvm_install_gem_specs @rvm_install_gem_specs end |
.rvm_install_rubies ⇒ Object
Returns the value of attribute rvm_install_rubies.
251 252 253 |
# File 'lib/cuken/api/rvm/wip.rb', line 251 def rvm_install_rubies @rvm_install_rubies end |
Class Method Details
._each_rvmrc_rubie ⇒ Object
done
466 467 468 469 470 471 472 473 |
# File 'lib/cuken/api/rvm/wip.rb', line 466 def _each_rvmrc_rubie _rvmrc_rubies.each do |ary| RVM.use(ary[0]) yield ary[0] end ensure RVM.reset_current! end |
._rvm_gem_available?(spec) ⇒ Object
done
547 548 549 550 |
# File 'lib/cuken/api/rvm/wip.rb', line 547 def _rvm_gem_available?(spec) gem, version = spec RVM.ruby_eval("require 'rubygems' ; print Gem.available?('#{gem}','#{version}')").stdout == 'true' end |
._rvm_install_rubie(rubie) ⇒ Object
done
428 429 430 431 432 433 |
# File 'lib/cuken/api/rvm/wip.rb', line 428 def _rvm_install_rubie(rubie) std_msg = "info: Rubie #{rubie} installed." err_msg = "Failed #{rubie} install! Check RVM logs here: #{RVM.path}/log/#{rubie}" puts "info: Rubie #{rubie} installation inprogress. This couldtake awhile..." RVM.install(rubie, ) ? puts(std_msg) : abort(err_msg) end |
._rvm_load ⇒ Object
done
419 420 421 422 423 424 425 |
# File 'lib/cuken/api/rvm/wip.rb', line 419 def _rvm_load @rvm_setup = false rvm_lib_path = rvm_path + "lib" rescue return $LOAD_PATH.unshift(rvm_lib_path.to_s) unless $LOAD_PATH.include?(rvm_lib_path.to_s) require 'rvm' @rvm_setup = defined?(RVM) ? true : false end |
._rvmrc_create_gemsets ⇒ Object
done
476 477 478 479 480 481 482 483 484 |
# File 'lib/cuken/api/rvm/wip.rb', line 476 def _rvmrc_create_gemsets _rvmrc_gemsets.each do |hsh| RVM.use hsh[0] hsh[1][:gemsets].each do |gmst| # TODO: Post refactor #RVM.gemset.create([gmst]) end end end |
._rvmrc_gemsets ⇒ Object
done
459 460 461 462 463 |
# File 'lib/cuken/api/rvm/wip.rb', line 459 def _rvmrc_gemsets default = Hash.new{|hsh,ky| hsh[ky] = {:alias => "cuken-#{ky}"}} @rvmrc_rubies_gemsets ||= rvmrc_rubies_gemsets(@rvmrc_root_path) @rvmrc_gemsets = @rvmrc_rubies_gemsets.inject(default){|h,(k,v)| h[k]; h[k][:gemsets]=v; h } end |
._rvmrc_install_gem(rubie, spec) ⇒ Object
done
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/cuken/api/rvm/wip.rb', line 487 def _rvmrc_install_gem(rubie, spec) gem, version = spec _rvmrc_gemsets.each do |hsh| rubie = hsh[0] hsh[1][:gemsets].each do |gmst| if RVM.gemset.instance_of? ::RVM::Environment::GemsetWrapper #RVM.gemset.create([gmst]) RVM.gemset.use(gmst) if _rvm_gem_available?(spec) puts "info: Gem #{gem}-#{version} already installed in #{rvm_current_name}." else puts "info: Installing gem #{gem}-#{version} in #{rvm_current_name}..." RVM.run("rvm --create use #{rubie}@#{gmst}; gem install #{gem} -v#{version} #{}") end end end end end |
._rvmrc_rubies ⇒ Object
done
452 453 454 455 456 |
# File 'lib/cuken/api/rvm/wip.rb', line 452 def _rvmrc_rubies default = Hash.new{|hsh,ky| hsh[ky] = {:alias => "cuken-#{ky}"}} @rvmrc_rubies_gemsets ||= rvmrc_rubies_gemsets(@rvmrc_root_path) @rvmrc_rubies = @rvmrc_rubies_gemsets.keys.inject(default){|h,(k,v)| h[k]; h } end |
.run_simple_gemset(cmd_str, options = {}) ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/cuken/api/rvm/wip.rb', line 255 def run_simple_gemset(cmd_str, = {} ) # RVM 1.6.5 is not generating rvm-legal code when given a command str so we write to a temp file tmpfile = ::Tempfile.open("cuken_#{__method__.to_s}_"){ |f| f.puts(cmd_str);f } tmpfile.close Pathname(tmpfile).chmod(0700) FileUtils.copy(tmpfile,tmpfile.path+'.bak') @run_simple_gemset_result = nil begin case when .key?(:ruby) && .key?(:gemset) full_gemset_string = "#{[:ruby]}@#{[:gemset]}" when .key?(:ruby) && !.key?(:gemset) full_gemset_string = "#{[:ruby]}@#{RVM.current.gemset.name}" when !.key?(:ruby) && .key?(:gemset) full_gemset_string = "#{RVM.current.[/(.*)@/,1]}@#{[:gemset]}" when !.key?(:ruby) && !.key?(:gemset) full_gemset_string = RVM.current. else full_gemset_string = RVM.current. end raise(::ArgumentError, "The RVM gemset #{full_gemset_string} is not present.") unless ::RVM.list_gemsets.include?(full_gemset_string) ::RVM.environment(full_gemset_string) do |env| if @announce_env announce_or_puts("Ruby environment for #{::RVM.current.}:") announce_or_puts("#{env.info.inspect}") end @run_simple_gemset_result = env.ruby(tmpfile, ) #sin = @run_simple_gemset_result.command #sout = @run_simple_gemset_result.stdout #serr = @run_simple_gemset_result.stderr #estat = @run_simple_gemset_result.exit_status end rescue ::Exception => e puts e. puts e.backtrace.join('\n') raise rescue ::ArgumentError => e puts "Exception raised by run_simple_gemset(#{cmd_str}, #{})" puts "Script executed from #{tmpfile.to_s}:\n#{tmpfile.open.readlines}" puts "Exception: #{e.}" puts e.backtrace.join('\n') raise e ensure tmpfile.unlink end @run_simple_gemset_result.inspect end |
.rvm_create_gemsets ⇒ Object
324 325 326 |
# File 'lib/cuken/api/rvm/wip.rb', line 324 def rvm_create_gemsets @rvm_create_gemsets ||= [] end |
.rvm_current_name ⇒ Object
307 308 309 |
# File 'lib/cuken/api/rvm/wip.rb', line 307 def rvm_current_name RVM.current. end |
.rvm_current_rubie_info ⇒ Object
done
395 396 397 |
# File 'lib/cuken/api/rvm/wip.rb', line 395 def rvm_current_rubie_info rvmrc_rubies[_rvm_current_rubie_name] end |
.rvm_environment_vars ⇒ Object
done
525 526 527 528 529 530 531 532 533 534 |
# File 'lib/cuken/api/rvm/wip.rb', line 525 def rvm_environment_vars if rvm_for_macports? {'CC' => '/usr/bin/gcc-4.2', 'CFLAGS' => '-O2 -arch x86_64', 'LDFLAGS' => '-L/opt/local/lib -arch x86_64', 'CPPFLAGS' => '-I/opt/local/include'} else {} end end |
.rvm_for_macports? ⇒ Object
done
537 538 539 |
# File 'lib/cuken/api/rvm/wip.rb', line 537 def rvm_for_macports? `uname`.strip == 'Darwin' && `which port`.present? end |
.rvm_gemset_paths(root_path = '/usr/src/cuken') ⇒ Object
349 350 351 352 353 354 355 356 357 |
# File 'lib/cuken/api/rvm/wip.rb', line 349 def rvm_gemset_paths(root_path='/usr/src/cuken') rpn = Pathname(root_path) rvmrc_dirs = [] Dir.glob((rpn + '**' + '.rvmrc').to_s).each do |d| dn = File.dirname(d) rvmrc_dirs << dn if File.directory?(dn) end rvmrc_dirs end |
.rvm_install_gemspecs ⇒ Object
320 321 322 |
# File 'lib/cuken/api/rvm/wip.rb', line 320 def rvm_install_gemspecs @rvm_install_gemspecs ||= [['bundler', '1.0.10']] end |
.rvm_install_options ⇒ Object
done
542 543 544 |
# File 'lib/cuken/api/rvm/wip.rb', line 542 def { } end |
.rvm_loaded? ⇒ Boolean
done
345 346 347 |
# File 'lib/cuken/api/rvm/wip.rb', line 345 def rvm_loaded? _rvm_load end |
.rvm_local_install? ⇒ Boolean
341 342 343 |
# File 'lib/cuken/api/rvm/wip.rb', line 341 def rvm_local_install? rvm_path.dirname.realpath.directory? end |
.rvm_path ⇒ Object
wip
336 337 338 339 |
# File 'lib/cuken/api/rvm/wip.rb', line 336 def rvm_path pn = Pathname.new(File.(ENV['rvm_path'] || '~/.rvm')) pn.exist? ? pn : raise(RuntimeError, "Could not find RVM's .rvm folder (#{pn})", caller) end |
.rvm_requested_gemset ⇒ Object
328 329 330 |
# File 'lib/cuken/api/rvm/wip.rb', line 328 def rvm_requested_gemset(gemset) @rvm_requested_gemset = gemset end |
.rvm_rubies_setup(root_path = '/usr/src/cuken') ⇒ Object
wip
380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/cuken/api/rvm/wip.rb', line 380 def rvm_rubies_setup(root_path='/usr/src/cuken') rvm_loaded? ? true : raise(RuntimeError, "RVM library not loaded.", caller) @rvmrc_rubies_gemsets ? true : rvmrc_rubies_gemsets(root_path) @rvmrc_rubies_gemsets.keys.each do |rubie| if RVM.list_strings.include?(rubie) puts "info: Rubie #{rubie} already installed." else with_rvm_environment_vars do _rvm_install_rubie(rubie) end end RVM.alias_create(rvmrc_rubies[rubie][:alias], "#{rubie}@#{rvm_requested_gemset}") unless rubie == rvmrc_rubies[rubie][:alias] end end |
.rvmrc(path) ⇒ Object
303 304 305 |
# File 'lib/cuken/api/rvm/wip.rb', line 303 def rvmrc(path) @rvmrc ||= RvmrcProcessor.new(path) end |
.rvmrc_extract_gemset(rvmrc) ⇒ Object
done
447 448 449 |
# File 'lib/cuken/api/rvm/wip.rb', line 447 def rvmrc_extract_gemset(rvmrc) rvmrc[/gemset_id=\"(.*)\"/, 1] end |
.rvmrc_extract_ruby(rvmrc) ⇒ Object
done
442 443 444 |
# File 'lib/cuken/api/rvm/wip.rb', line 442 def rvmrc_extract_ruby(rvmrc) rvmrc[/ruby_id=\"(.*)\"/, 1] end |
.rvmrc_extract_ruby_gemset(rvmrc) ⇒ Object
done
437 438 439 |
# File 'lib/cuken/api/rvm/wip.rb', line 437 def rvmrc_extract_ruby_gemset(rvmrc) "#{rvmrc_extract_ruby(rvmrc)}@#{rvmrc_extract_gemset(rvmrc)}" end |
.rvmrc_gems_install(root_path) ⇒ Object
Install @rvm_install_gemspecs gemspec using rubies and gemsets found in .rvmrc files. done
402 403 404 405 406 407 408 |
# File 'lib/cuken/api/rvm/wip.rb', line 402 def rvmrc_gems_install(root_path) @rvmrc_root_path = root_path _rvmrc_create_gemsets _each_rvmrc_rubie do |rubie| rvm_install_gemspecs.each { |spec| _rvmrc_install_gem(rubie, spec) } end end |
.rvmrc_gemsets_install(root_path) ⇒ Object
410 411 412 413 414 415 |
# File 'lib/cuken/api/rvm/wip.rb', line 410 def rvmrc_gemsets_install(root_path) @rvmrc_root_path = root_path _each_rvmrc_rubie do |rubie| rvm_install_gemspecs.each { |spec| _rvmrc_install_gem(rubie, spec) } end end |
.rvmrc_rubies ⇒ Object
done
376 377 378 |
# File 'lib/cuken/api/rvm/wip.rb', line 376 def rvmrc_rubies @rvmrc_rubies ||= _rvmrc_rubies #.keys.map{ |rubie| "#{rubie}@#{rvm_requested_gemset}" } end |
.rvmrc_rubies_gemsets(root_path = '/usr/src/cuken') ⇒ Object
done
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/cuken/api/rvm/wip.rb', line 360 def rvmrc_rubies_gemsets(root_path='/usr/src/cuken') @rvmrc_rubies_gemsets = Hash.new([]) arry=rvm_gemset_paths(root_path) arry.each do |dir| Dir.glob(dir + '/*.gems').each do |fn| gsn = File.basename(fn,'.gems').to_s rvmrc = File.new(File.dirname(fn) + '/.rvmrc').read rube = rvmrc_extract_ruby(rvmrc) egsn = rvmrc_extract_gemset(rvmrc) @rvmrc_rubies_gemsets[rube] = [] unless @rvmrc_rubies_gemsets.key? rube @rvmrc_rubies_gemsets[rube] << gsn if gsn == egsn end end @rvmrc_rubies_gemsets end |
.set_environment_vars(vars) ⇒ Object
done
508 509 510 |
# File 'lib/cuken/api/rvm/wip.rb', line 508 def set_environment_vars(vars) vars.each { |k,v| ENV[k] = v } end |
.with_rvm_environment_vars ⇒ Object
done
513 514 515 516 517 518 519 520 521 522 |
# File 'lib/cuken/api/rvm/wip.rb', line 513 def with_rvm_environment_vars my_vars = rvm_environment_vars puts my_vars current_vars = my_vars.inject({}) { |cvars,kv| k,v = kv ; cvars[k]= ENV[k] ; cvars } puts current_vars set_environment_vars(my_vars) yield ensure set_environment_vars(current_vars) end |
Instance Method Details
#rvm ⇒ Object
41 42 43 |
# File 'lib/cuken/api/rvm.rb', line 41 def rvm @rvm ||= RvmHelper.new end |