Skip to content

Commit

Permalink
Merge pull request #154 from fnichol/skip-requirements
Browse files Browse the repository at this point in the history
Call rvm by path for rvm_ruby install/uninstall/remove.
  • Loading branch information
fnichol committed Jan 25, 2013
2 parents dea8328 + 4c3e36a commit 517723d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 7 additions & 3 deletions libraries/rvm_chef_user_environment.rb
Expand Up @@ -21,9 +21,11 @@

def create_rvm_chef_user_environment
klass = Class.new(::RVM::Environment) do
attr_reader :user
attr_reader :user, :source_environment

def initialize(user = nil, environment_name = "default", options = {})
@source_environment = options.delete(:source_environment)
@source_environment = true if @source_environment.nil?
@user = user
# explicitly set rvm_path if user is set
if @user.nil?
Expand All @@ -36,8 +38,10 @@ def initialize(user = nil, environment_name = "default", options = {})
@environment_name = environment_name
@shell_wrapper = ::RVM::Shell::ChefWrapper.new(@user)
@shell_wrapper.setup do |s|
source_rvm_environment
use_rvm_environment
if source_environment
source_rvm_environment
use_rvm_environment
end
end
end

Expand Down
12 changes: 8 additions & 4 deletions providers/ruby.rb
Expand Up @@ -25,7 +25,11 @@
def load_current_resource
@rubie = normalize_ruby_string(select_ruby(new_resource.ruby_string))
@ruby_string = new_resource.ruby_string
@rvm_env = ::RVM::ChefUserEnvironment.new(new_resource.user, "default", :rvm_rubygems_version => new_resource.rubygems_version)
@rvm_env = ::RVM::ChefUserEnvironment.new(
new_resource.user, "default",
:rvm_rubygems_version => new_resource.rubygems_version,
:source_environment => false
)
end

action :install do
Expand All @@ -35,7 +39,7 @@ def load_current_resource
Chef::Log.debug("rvm_ruby[#{@rubie}] is already installed, so skipping")
else
install_start = Time.now
install_options = {}
install_options = {:rvm_by_path => true}
install_options[:patch] = new_resource.patch if new_resource.patch

install_ruby_dependencies @rubie
Expand Down Expand Up @@ -71,7 +75,7 @@ def load_current_resource
if ruby_installed?(@rubie)
Chef::Log.info("Uninstalling rvm_ruby[#{@rubie}]")

if @rvm_env.uninstall(@rubie)
if @rvm_env.uninstall(@rubie, :rvm_by_path => true)
update_installed_rubies
Chef::Log.debug("Uninstallation of rvm_ruby[#{@rubie}] was successful.")
new_resource.updated_by_last_action(true)
Expand All @@ -90,7 +94,7 @@ def load_current_resource
if ruby_installed?(@rubie)
Chef::Log.info("Removing rvm_ruby[#{@rubie}]")

if @rvm_env.remove(@rubie)
if @rvm_env.remove(@rubie, :rvm_by_path => true)
update_installed_rubies
Chef::Log.debug("Removal of rvm_ruby[#{@rubie}] was successful.")
new_resource.updated_by_last_action(true)
Expand Down
4 changes: 3 additions & 1 deletion recipes/default.rb
Expand Up @@ -18,7 +18,9 @@
#

# install rvm api gem during chef compile phase
chef_gem 'rvm'
chef_gem 'rvm' do
version '>= 1.11.3.6'
end
require 'rvm'

create_rvm_shell_chef_wrapper
Expand Down

0 comments on commit 517723d

Please sign in to comment.