|
27 | 27 | ruby_string.sub!(/default/, current_ruby_default) |
28 | 28 | end |
29 | 29 |
|
30 | | - # ensure ruby is installed and gemset exists |
31 | | - e = rvm_environment ruby_string do |
32 | | - action :nothing |
| 30 | + if new_resource.global |
| 31 | + # add gem entry into global.gems |
| 32 | + update_global_gems_file :create |
| 33 | + |
| 34 | + # install gem in all rubies in global gemset |
| 35 | + installed_rubies.each do |rubie| |
| 36 | + gem_package_wrapper :install, "#{rubie}@global" |
| 37 | + end |
| 38 | + else |
| 39 | + # ensure ruby is installed and gemset exists |
| 40 | + e = rvm_environment ruby_string do |
| 41 | + action :nothing |
| 42 | + end |
| 43 | + e.run_action(:create) |
| 44 | + |
| 45 | + gem_package_wrapper :install |
33 | 46 | end |
34 | | - e.run_action(:create) |
| 47 | +end |
35 | 48 |
|
| 49 | +## |
| 50 | +# Wraps the gem_package provider for rubygems |
| 51 | +# |
| 52 | +# @param [Symbol] action to be performed with gem_package provider |
| 53 | +# @param [optional, String, #to_s] the fully qualifed rvm string |
| 54 | +def gem_package_wrapper(exec_action, ruby_string=new_resource.ruby_string) |
36 | 55 | g = gem_package new_resource.gem do |
37 | 56 | gem_binary "rvm #{ruby_string} gem" |
38 | 57 | source new_resource.source if new_resource.source |
39 | 58 | options new_resource.options if new_resource.options |
40 | 59 | version new_resource.version if new_resource.version |
41 | 60 | action :nothing |
42 | 61 | end |
43 | | - g.run_action(:install) |
| 62 | + g.run_action(exec_action) |
| 63 | +end |
| 64 | + |
| 65 | +## |
| 66 | +# Updates global.gems file to create or remove a gem entry |
| 67 | +# |
| 68 | +# @oaram [Symbol] action to :create or :remove the gem from the file |
| 69 | +def update_global_gems_file(exec_action) |
| 70 | + global_gems_file = "#{node[:rvm][:root_path]}/gemsets/global.gems" |
| 71 | + gem = new_resource.gem |
| 72 | + |
| 73 | + if exec_action == :create |
| 74 | + e = execute "Add #{gem} to #{global_gems_file}" do |
| 75 | + user "root" |
| 76 | + group "rvm" |
| 77 | + command %{echo "#{gem}" >> "#{global_gems_file}"} |
| 78 | + not_if %{grep -q "^#{gem}" "#{global_gems_file}"} |
| 79 | + action :nothing |
| 80 | + end |
| 81 | + e.run_action(:run) |
| 82 | + end |
44 | 83 | end |
0 commit comments