Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making all set actions explicit. #46

Merged
merged 3 commits into from Oct 15, 2011
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions libraries/chef_rvm_set_helpers.rb
@@ -0,0 +1,15 @@
class Chef
module RVM
module SetHelpers
def rvm_do(user = nil)
# Use Gem's version comparing code to compare the two strings
if Gem::Version.new(VersionCache.fetch_version(user)) <= Gem::Version.new("1.8.6")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fnichol: If you hate abusing Gem this way, we can pull in versionomy (https://github.com/dazuma/versionomy) to do it instead.

"exec"
else
"do"
end
end

end
end
end
39 changes: 39 additions & 0 deletions libraries/chef_rvm_version_helpers.rb
@@ -0,0 +1,39 @@
class Chef
module RVM
module ShellHelpers
# stub to satisfy VersionCache (library load order not guarenteed)
end

module VersionHelpers
def rvm_version(user = nil)
VersionCache.fetch_version(user)
end
end

class VersionCache
class << self
include Chef::Mixin::ShellOut
include Chef::RVM::ShellHelpers
end

def self.fetch_version(user = nil)
@@version ||= rvm_version(user)
end

def self.rvm_version(user = nil)
cmd = "rvm version | cut -d ' ' -f 2"

if user
user_dir = Etc.getpwnam(user).dir
environment = { 'USER' => user, 'HOME' => user_dir }
else
user_dir = nil
environment = nil
end

version = shell_out!(
rvm_wrap_cmd(cmd, user_dir), :env => environment).stdout
end
end
end
end
13 changes: 9 additions & 4 deletions libraries/rvm_rubygems_package.rb
Expand Up @@ -24,15 +24,20 @@ module RVM
module ShellHelpers
# stub to satisfy RVMRubygems (library load order not guarenteed)
end
module SetHelpers
# stub to satisfy RVMRubygems (library load order not guarenteed)
end
end

class Provider
class Package
class RVMRubygems < Chef::Provider::Package::Rubygems
include Chef::RVM::ShellHelpers
include Chef::RVM::SetHelpers

class RVMGemEnvironment < AlternateGemEnvironment
include Chef::RVM::ShellHelpers
include Chef::RVM::SetHelpers

attr_reader :ruby_strings, :user

Expand All @@ -44,7 +49,7 @@ def initialize(gem_binary_location, ruby_strings, user = nil)

def gem_paths
cmd = "rvm #{ruby_strings.join(',')} "
cmd << "exec #{@gem_binary_location} env gempath"
cmd << "#{rvm_do} #{@gem_binary_location} env gempath"

if user
user_dir = Etc.getpwnam(user).dir
Expand All @@ -64,7 +69,7 @@ def gem_paths

def gem_platforms
cmd = "rvm #{ruby_strings.join(',')} "
cmd << "exec #{@gem_binary_location} env"
cmd << "#{rvm_do} #{@gem_binary_location} env"

if user
user_dir = Etc.getpwnam(user).dir
Expand Down Expand Up @@ -134,7 +139,7 @@ def install_via_gem_command(name, version)
src = @new_resource.source &&
" --source=#{@new_resource.source} --source=http://rubygems.org"

cmd = %{rvm #{ruby_strings.join(',')} #{gem_binary_path}}
cmd = %{rvm #{ruby_strings.join(',')} #{rvm_do} #{gem_binary_path}}
cmd << %{ install #{name} -q --no-rdoc --no-ri -v "#{version}"}
cmd << %{#{src}#{opts}}

Expand All @@ -154,7 +159,7 @@ def remove_package(name, version)
end

def uninstall_via_gem_command(name, version)
cmd = %{rvm #{ruby_strings.join(',')} #{gem_binary_path}}
cmd = %{rvm #{ruby_strings.join(',')} #{rvm_do} #{gem_binary_path}}
cmd << %{ uninstall #{name} -q -x -I}
if version
cmd << %{ -v "#{version}"#{opts}}
Expand Down