Class: Cuken::Api::Rvm::RvmrcProcessor
- Inherits:
-
Object
- Object
- Cuken::Api::Rvm::RvmrcProcessor
- Defined in:
- lib/cuken/api/rvm/wip.rb
Instance Attribute Summary collapse
-
#gemspecs_to_install ⇒ Object
Return array of [gem_name, gem_version] to be installed into all gemsets found in .rvmrc files.
Instance Method Summary collapse
-
#all_gemsets(root_path = @root_path) ⇒ Object
returns hash of all gemsets, per-Ruby, in all .rvmrc files beneath a root folder.
-
#all_rubies(root_path = @root_path) ⇒ Object
returns array of all rubies in all .rvmrc files beneath a root folder.
-
#all_rubies_gemsets(root_path = @root_path) ⇒ Object
returns rubies and gemsets from .rvmrc files glob’ed below a root folder.
-
#create_gemsets ⇒ Object
create gemsets parsed from all .rvmrc files beneath a root folder.
-
#current_ruby_info(rubie) ⇒ Object
return the parsed .rvmrc info for the current ruby.
-
#each_ruby ⇒ Object
yield a block in the environment of each in the installed rubies, and return current Ruby string even if the given block raises.
-
#find_gems_files(rvmrc_root) ⇒ Object
return an array of *.gems file paths found beneath a root folder.
-
#find_rvmrc_files(rvmrc_root) ⇒ Object
return an array of .rvmrc file paths found beneath a root folder.
-
#find_rvmrc_paths(rvmrc_root) ⇒ Object
return an arry of paths containing .rvmrc files.
-
#gem_install_options ⇒ Object
return the options string for Ruby’s ‘gem install…` CLI.
-
#gems_install ⇒ Object
Install @gemspecs_to_install contents using rubies and gemsets found in .rvmrc files.
-
#initialize(path) ⇒ RvmrcProcessor
constructor
A new instance of RvmrcProcessor.
-
#install_gem(rubie, spec) ⇒ Object
install given gem into all ruby+gemsets parsed from .rvmrc files beneath a root folder.
- #rvm_path ⇒ Object
-
#rvmrc ⇒ Object
return the .rvmrc file contents.
-
#rvmrc_gemset_name ⇒ Object
return gemset name parsed from .rvmrc file contents.
-
#rvmrc_read(path) ⇒ Object
read the .rvmrc file contents into @rvmrc.
-
#rvmrc_ruby_gemset(rvmrc) ⇒ Object
return concatenated string of rvmrc_ruby@rvmrc_gemset.
-
#rvmrc_ruby_name ⇒ Object
return ruby name parsed from .rvmrc file contents.
-
#setup_rubies ⇒ Object
Does not install existing RVM rubies that are listed in the .rvmrc files raise an error if RVM’s install root does not exist.
Constructor Details
#initialize(path) ⇒ RvmrcProcessor
Returns a new instance of RvmrcProcessor.
12 13 14 15 |
# File 'lib/cuken/api/rvm/wip.rb', line 12 def initialize(path) @root_path = ::File.directory?(path) ? path : File.dirname(path) rvmrc_read(path) end |
Instance Attribute Details
#gemspecs_to_install ⇒ Object
Return array of [gem_name, gem_version] to be installed into all gemsets found in .rvmrc files. Default is Bundler versio 1.0.10
122 123 124 |
# File 'lib/cuken/api/rvm/wip.rb', line 122 def gemspecs_to_install @gemspecs_to_install ||= [['bundler', '1.0.10']] end |
Instance Method Details
#all_gemsets(root_path = @root_path) ⇒ Object
returns hash of all gemsets, per-Ruby, in all .rvmrc files beneath a root folder
85 86 87 88 89 |
# File 'lib/cuken/api/rvm/wip.rb', line 85 def all_gemsets(root_path=@root_path) default = Hash.new{|hsh,ky| hsh[ky] = {:ruby_alias => "cuken_#{ky}"}} @all_rubies_gemsets ||= all_rubies_gemsets(root_path) @all_gemsets = @all_rubies_gemsets.inject(default){|h,(k,v)| h[k]; h[k][:gemsets]=v; h } end |
#all_rubies(root_path = @root_path) ⇒ Object
returns array of all rubies in all .rvmrc files beneath a root folder
92 93 94 95 |
# File 'lib/cuken/api/rvm/wip.rb', line 92 def all_rubies(root_path=@root_path) @all_rubies_gemsets ||= all_rubies_gemsets(root_path) @all_rubies = @all_rubies_gemsets.keys end |
#all_rubies_gemsets(root_path = @root_path) ⇒ Object
returns rubies and gemsets from .rvmrc files glob’ed below a root folder.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cuken/api/rvm/wip.rb', line 66 def all_rubies_gemsets(root_path=@root_path) @all_rubies_gemsets = Hash.new([]) arry=find_rvmrc_paths(root_path) arry.each do |dir| Dir.glob(dir + '/*.gems').each do |fn| gsn = File.basename(fn,'.gems').to_s rvmrc_read(dir + '/.rvmrc') rube = rvmrc_ruby_name egsn = rvmrc_gemset_name @all_rubies_gemsets[rube] = [] unless @all_rubies_gemsets.key? rube if gsn == egsn @all_rubies_gemsets[rube] << {:ruby_alias => "cuken_#{rube}",:gemset_alias => "cuken_#{gsn}", :gemset_name => gsn, :gemset_path => fn} end end end @all_rubies_gemsets end |
#create_gemsets ⇒ Object
create gemsets parsed from all .rvmrc files beneath a root folder
112 113 114 115 116 117 118 |
# File 'lib/cuken/api/rvm/wip.rb', line 112 def create_gemsets each_ruby do |rubie| all_gemsets(@root_path)[rubie][:gemsets].each do |hsh| ::RVM.gemset.create([hsh[:gemset_name]]) end end end |
#current_ruby_info(rubie) ⇒ Object
return the parsed .rvmrc info for the current ruby
158 159 160 161 |
# File 'lib/cuken/api/rvm/wip.rb', line 158 def current_ruby_info(rubie) @all_rubies_gemsets ||= all_rubies_gemsets @all_rubies_gemsets[rubie] end |
#each_ruby ⇒ Object
yield a block in the environment of each in the installed rubies, and return current Ruby string even if the given block raises
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/cuken/api/rvm/wip.rb', line 99 def each_ruby begin all_rubies(@root_path).each do |rubie| RVM.use(rubie) yield rubie end rescue ensure RVM.reset_current! end end |
#find_gems_files(rvmrc_root) ⇒ Object
return an array of *.gems file paths found beneath a root folder
60 61 62 |
# File 'lib/cuken/api/rvm/wip.rb', line 60 def find_gems_files(rvmrc_root) Dir.glob(rvmrc_root + '/**' + '/*.gems') end |
#find_rvmrc_files(rvmrc_root) ⇒ Object
return an array of .rvmrc file paths found beneath a root folder
45 46 47 |
# File 'lib/cuken/api/rvm/wip.rb', line 45 def find_rvmrc_files(rvmrc_root) Dir.glob(rvmrc_root + '/**' + '/.rvmrc') end |
#find_rvmrc_paths(rvmrc_root) ⇒ Object
return an arry of paths containing .rvmrc files
50 51 52 53 54 55 56 57 |
# File 'lib/cuken/api/rvm/wip.rb', line 50 def find_rvmrc_paths(rvmrc_root) root = File.directory?(rvmrc_root) ? rvmrc_root : File.dirname(rvmrc_root) dirs = [] find_rvmrc_files(root).each do |path| dirs << File.dirname(File.(path)) if File.file?(path) end dirs end |
#gem_install_options ⇒ Object
return the options string for Ruby’s ‘gem install…` CLI
136 137 138 139 |
# File 'lib/cuken/api/rvm/wip.rb', line 136 def @gem_install_options ||= ['no_ri', 'no_rdoc'] "--" + @gem_install_options.join(' --') end |
#gems_install ⇒ Object
Install @gemspecs_to_install contents using rubies and gemsets found in .rvmrc files.
128 129 130 131 132 133 |
# File 'lib/cuken/api/rvm/wip.rb', line 128 def gems_install create_gemsets each_ruby do |rubie| gemspecs_to_install.each { |spec| install_gem(rubie, spec) } end end |
#install_gem(rubie, spec) ⇒ Object
install given gem into all ruby+gemsets parsed from .rvmrc files beneath a root folder
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/cuken/api/rvm/wip.rb', line 142 def install_gem(rubie, spec) gem, version = spec all_gemsets.each do |rubie, hsh| hsh[:gemsets].each do |h| if 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.gemset.use(h[:gemset_alias]) RVM.run("rvm --create use #{h[:gemset_alias]}; gem install #{gem} -v#{version} #{}") end end end end |
#rvm_path ⇒ Object
163 164 165 166 |
# File 'lib/cuken/api/rvm/wip.rb', line 163 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 |
#rvmrc ⇒ Object
return the .rvmrc file contents
25 26 27 |
# File 'lib/cuken/api/rvm/wip.rb', line 25 def rvmrc @rvmrc end |
#rvmrc_gemset_name ⇒ Object
return gemset name parsed from .rvmrc file contents
35 36 37 |
# File 'lib/cuken/api/rvm/wip.rb', line 35 def rvmrc_gemset_name extract_gemset(rvmrc) end |
#rvmrc_read(path) ⇒ Object
read the .rvmrc file contents into @rvmrc
18 19 20 21 22 |
# File 'lib/cuken/api/rvm/wip.rb', line 18 def rvmrc_read(path) fn = ::File.directory?(path) ? path + '/.rvmrc' : path @rvmrc = ::File.new(fn).read return true if @rvmrc.size > 0 end |
#rvmrc_ruby_gemset(rvmrc) ⇒ Object
return concatenated string of rvmrc_ruby@rvmrc_gemset
40 41 42 |
# File 'lib/cuken/api/rvm/wip.rb', line 40 def rvmrc_ruby_gemset(rvmrc) "#{extract_rubie(rvmrc)}@#{extract_gemset(rvmrc)}" end |
#rvmrc_ruby_name ⇒ Object
return ruby name parsed from .rvmrc file contents
30 31 32 |
# File 'lib/cuken/api/rvm/wip.rb', line 30 def rvmrc_ruby_name extract_rubie(rvmrc) end |
#setup_rubies ⇒ Object
Does not install existing RVM rubies that are listed in the .rvmrc files raise an error if RVM’s install root does not exist
169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/cuken/api/rvm/wip.rb', line 169 def setup_rubies rvm_loaded? ? true : raise(RuntimeError, "RVM library not loaded.", caller) @all_rubies_gemsets ||= all_rubies_gemsets(@root_path) @all_rubies_gemsets.keys.each do |rubie| if RVM.list_strings.include?(rubie) puts "info: Rubie #{rubie} already installed." else with_rvm_environment_vars do install_rubie(rubie) end end RVM.alias_create(current_ruby_info(rubie)[0][:ruby_alias], "#{rubie}") unless rubie == current_ruby_info(rubie)[0][:ruby_alias] end end |