Skip to content

Commit 17cc5a4

Browse files
committed
Begin to refactor to LWRP resource/providers and to use RVM gem.
1 parent fe4dc88 commit 17cc5a4

11 files changed

Lines changed: 156 additions & 19 deletions

File tree

‎README.rdoc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Author:: Fletcher Nichol (<fnichol@nichol.ca>)
2121
Contributors:: Bram Swenson (<bram@craniumisajar.com>)
2222
Contributors:: Phil Cohen (http://phlippers.net/)
2323

24-
Copyright:: 2010, Fletcher Nichol
24+
Copyright:: 2010, 2011, Fletcher Nichol
2525

2626
Licensed under the Apache License, Version 2.0 (the "License");
2727
you may not use this file except in compliance with the License.

‎attributes/default.rb‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
#
2+
# Cookbook Name:: rvm
3+
# Attributes:: default
4+
#
5+
# Author:: Fletcher Nichol <fnichol@nichol.ca>
6+
#
7+
# Copyright 2010, 2011, Fletcher Nichol
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
#
21+
122
default[:rvm][:root_path] = "/usr/local/rvm"
223
default[:rvm][:group_users] = []
324
default[:rvm][:rvmrc] = Hash.new

‎definitions/rvm_gem.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# Licensed under the Apache License, Version 2.0 (the "License");
1313
# you may not use this file except in compliance with the License.
1414
# You may obtain a copy of the License at
15-
#
15+
#
1616
# http://www.apache.org/licenses/LICENSE-2.0
17-
#
17+
#
1818
# Unless required by applicable law or agreed to in writing, software
1919
# distributed under the License is distributed on an "AS IS" BASIS,
2020
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

‎libraries/ruby.rb‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Cookbook Name:: rvm
3+
# Library:: ruby
4+
#
5+
# Author:: Fletcher Nichol <fnichol@nichol.ca>
6+
#
7+
# Copyright 2011, Fletcher Nichol
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
#
21+
22+
begin
23+
require 'rvm'
24+
rescue LoadError
25+
Chef::Log.warn("Missing gem 'rvm'")
26+
end
27+
28+
##
29+
# Determines whether or not the given ruby is already installed
30+
#
31+
# @param [String, #to_s] the fully qualified RVM ruby string
32+
# @return [Boolean] is this ruby installed?
33+
def ruby_installed?(rubie)
34+
RVM.list_strings.include?(rubie)
35+
end

‎providers/ruby.rb‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# Cookbook Name:: rvm
3+
# Provider:: ruby
4+
#
5+
# Author:: Fletcher Nichol <fnichol@nichol.ca>
6+
#
7+
# Copyright 2011, Fletcher Nichol
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
#
21+
22+
action :install do
23+
rubie = new_resource.ruby_string
24+
25+
if ruby_installed?(rubie)
26+
Chef::Log.debug("RVM ruby #{rubie} is already installed, so skipping")
27+
else
28+
Chef::Log.info("RVM ruby #{rubie} installation in progress. " +
29+
"This could take awhile...")
30+
31+
if RVM.install(rubie)
32+
Chef::Log.info("Successful installation of RVM ruby #{rubie}")
33+
else
34+
Chef::Log.warn("Failed to install RVM ruby #{rubie}. " +
35+
"Check RVM logs here: #{RVM.path}/log/#{rubie}")
36+
end
37+
end
38+
end

‎recipes/default.rb‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,33 @@
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.
99
# You may obtain a copy of the License at
10-
#
10+
#
1111
# http://www.apache.org/licenses/LICENSE-2.0
12-
#
12+
#
1313
# Unless required by applicable law or agreed to in writing, software
1414
# distributed under the License is distributed on an "AS IS" BASIS,
1515
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
1818
#
1919

20+
require 'rubygems/dependency_installer'
21+
22+
# install rvm api gem during chef compile phase
23+
if Gem.source_index.find_name("rvm").empty?
24+
Chef::Log.info("Installing RVM gem")
25+
Gem::DependencyInstaller.new.install("rvm")
26+
begin
27+
Gem.activate("rvm")
28+
require 'rvm'
29+
rescue LoadError
30+
Chef::Application.fatal!(
31+
"There was a problem installing and loading the 'rvm' gem.")
32+
end
33+
else
34+
Chef::Log.debug("RVM gem was installed, so installation skipped")
35+
end
36+
2037
include_recipe "rvm::system"
2138
include_recipe "rvm::rubies"
2239
include_recipe "rvm::default_ruby"

‎recipes/default_ruby.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.
99
# You may obtain a copy of the License at
10-
#
10+
#
1111
# http://www.apache.org/licenses/LICENSE-2.0
12-
#
12+
#
1313
# Unless required by applicable law or agreed to in writing, software
1414
# distributed under the License is distributed on an "AS IS" BASIS,
1515
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

‎recipes/gems.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.
99
# You may obtain a copy of the License at
10-
#
10+
#
1111
# http://www.apache.org/licenses/LICENSE-2.0
12-
#
12+
#
1313
# Unless required by applicable law or agreed to in writing, software
1414
# distributed under the License is distributed on an "AS IS" BASIS,
1515
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

‎recipes/rubies.rb‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
# Cookbook Name:: rvm
33
# Recipe:: rubies
44
#
5-
# Copyright 2010, Fletcher Nichol
5+
# Copyright 2010, 2011, Fletcher Nichol
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.
99
# You may obtain a copy of the License at
10-
#
10+
#
1111
# http://www.apache.org/licenses/LICENSE-2.0
12-
#
12+
#
1313
# Unless required by applicable law or agreed to in writing, software
1414
# distributed under the License is distributed on an "AS IS" BASIS,
1515
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -48,10 +48,6 @@
4848
package pkg
4949
end
5050

51-
bash "install RVM ruby: #{ruby}" do
52-
user "root"
53-
code %{source /etc/profile.d/rvm.sh && rvm install #{ruby}}
54-
not_if %{bash -c "source /etc/profile.d/rvm.sh && rvm list strings | grep -q '^#{ruby}' >/dev/null"}
55-
end
51+
rvm_ruby ruby
5652
end
5753

‎recipes/system.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.
99
# You may obtain a copy of the License at
10-
#
10+
#
1111
# http://www.apache.org/licenses/LICENSE-2.0
12-
#
12+
#
1313
# Unless required by applicable law or agreed to in writing, software
1414
# distributed under the License is distributed on an "AS IS" BASIS,
1515
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

0 commit comments

Comments
 (0)