Skip to content

Commit

Permalink
Merge pull request #122 from walkamongus/rvm_autolibs_refactor
Browse files Browse the repository at this point in the history
Convert rvm_system_ruby autolib_mode to parameter
  • Loading branch information
carlossg committed Jun 8, 2016
2 parents d9bac19 + 543677b commit 984ac9f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
12 changes: 3 additions & 9 deletions lib/puppet/provider/rvm_system_ruby/rvm_system_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ def set_default
rvmcmd "alias", "create", "default", resource[:name]
end

def set_autolib_mode
begin
rvmcmd "autolibs", resource[:autolib_mode]
rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, "Could not set autolib mode: #{detail}"
end
end

private

def install
Expand All @@ -65,8 +57,10 @@ def install
ENV['no_proxy'] = resource[:no_proxy]
end
end
set_autolib_mode if resource.value(:autolib_mode)
options = Array(resource[:build_opts])
if resource[:autolibs_mode]
options << "--autolibs #{resource[:autolibs_mode]}"
end
if resource[:proxy_url] and !resource[:proxy_url].empty?
rvmcmd "install", resource[:name], "--proxy", resource[:proxy_url], *options
else
Expand Down
16 changes: 14 additions & 2 deletions lib/puppet/type/rvm_system_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,20 @@
defaultto false
end

newproperty(:autolib_mode) do
desc "Set RVM autolib mode"
newparam(:autolib_mode) do
desc "Set RVM autolib mode for the Ruby installation"

validate do |value|
modes = [
0, 'disable', 'disabled',
1, 'read', 'read-only',
2, 'fail', 'read-fail',
3, 'packages', 'install-packages',
4, 'enable', 'enabled',
]

fail("Invalid autolib mode: #{value}") unless modes.include? value
end
end

newparam(:mount_from) do
Expand Down
24 changes: 24 additions & 0 deletions spec/unit/puppet/type/rvm_system_ruby_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper'
require 'puppet'
require 'puppet/type/rvm_system_ruby'

describe Puppet::Type.type(:rvm_system_ruby) do
context 'with autolib_mode set' do
it 'should not raise error' do
expect do
Puppet::Type.type(:rvm_system_ruby).new(:name => 'ruby-1.9.3-p448', :autolib_mode => 'enabled')
end.not_to raise_error
end

it 'should set mode correctly' do
@system_ruby = Puppet::Type.type(:rvm_system_ruby).new(:name => 'jruby-1.7.6', :autolib_mode => 'read-fail')
expect(@system_ruby[:autolib_mode]).to eq('read-fail')
end
end

it 'should error on an incorrect autolib_mode' do
expect do
Puppet::Type.type(:rvm_system_ruby).new(:name => 'ruby-1.9.3-p448', :autolib_mode => 'foo')
end.to raise_error(Puppet::ResourceError, /Invalid autolib mode: foo/)
end
end

0 comments on commit 984ac9f

Please sign in to comment.