Skip to content

Commit

Permalink
Add initial rvm_environment and rvm_gem resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnichol committed Feb 13, 2011
1 parent 3c927fa commit 8ff1016
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 58 deletions.
35 changes: 0 additions & 35 deletions definitions/rvm_gem.rb

This file was deleted.

10 changes: 9 additions & 1 deletion libraries/helpers.rb
Expand Up @@ -68,6 +68,14 @@ def ruby_unknown?(rubie)
!ruby_known?(rubie)
end

##
# Fetches the current default ruby string, potentially with gemset
#
# @return [String] the fully qualified RVM ruby string, nil if none is set
def current_ruby_default
RVM.list_default
end

##
# Determines whether or not the given ruby is the default one
#
Expand All @@ -76,7 +84,7 @@ def ruby_unknown?(rubie)
def ruby_default?(rubie)
return false unless ruby_string_sane?(rubie)

current_default = RVM.list_default
current_default = current_ruby_default
return false if current_default.nil?
current_default.start_with?(rubie)
end
Expand Down
18 changes: 2 additions & 16 deletions providers/default_ruby.rb
Expand Up @@ -30,22 +30,8 @@
elsif ruby_default?(ruby_string)
Chef::Log.debug("rvm_ruby[#{ruby_string}] is already default, so skipping")
else
# install ruby if it is not installed
unless ruby_installed?(rubie)
r = rvm_ruby rubie do
action :nothing
end
r.run_action(:install)
end

# create gemset if it is not created
unless gemset_exists?(:ruby => rubie, :gemset => gemset)
g = rvm_gemset gemset do
ruby_string rubie
action :nothing
end
g.run_action(:create)
end
# ensure ruby is installed and gemset exists (if specified)
rvm_environment ruby_string

Chef::Log.info("Setting default ruby to rvm_ruby[#{ruby_string}]")
env = RVM::Environment.new
Expand Down
45 changes: 45 additions & 0 deletions providers/environment.rb
@@ -0,0 +1,45 @@
#
# Cookbook Name:: rvm
# Provider:: environment
#
# Author:: Fletcher Nichol <fnichol@nichol.ca>
#
# Copyright 2011, Fletcher Nichol
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

action :create do
ruby_string = new_resource.ruby_string
rubie = select_ruby(ruby_string)
gemset = select_gemset(ruby_string)

if ruby_unknown?(rubie)
Chef::Log.warn("rvm_environment[#{rubie}] is either not fully " +
"qualified or not known . Use `rvm list known` to get a full list.")
else
# ensure ruby version is installed
r = rvm_ruby rubie do
action :nothing
end

# ensure gemset is created, if specified
unless gemset.nil?
g = rvm_gemset gemset do
ruby_string rubie
action :nothing
end
g.run_action(:create)
end
end
end
44 changes: 44 additions & 0 deletions providers/gem.rb
@@ -0,0 +1,44 @@
#
# Cookbook Name:: rvm
# Provider:: gem
#
# Author:: Fletcher Nichol <fnichol@nichol.ca>
#
# Copyright 2011, Fletcher Nichol
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

action :install do
ruby_string = new_resource.ruby_string

# get the actual ruby string that corresponds to "default"
if ruby_string.start_with?("default")
ruby_string.sub!(/default/, current_ruby_default)
end

# ensure ruby is installed and gemset exists
e = rvm_environment ruby_string do
action :nothing
end
e.run_action(:create)

g = gem_package new_resource.gem do
gem_binary "rvm #{ruby_string} gem"
source new_resource.source if new_resource.source
options new_resource.options if new_resource.options
version new_resource.version if new_resource.version
action :nothing
end
g.run_action(:install)
end
14 changes: 8 additions & 6 deletions recipes/default.rb
Expand Up @@ -47,14 +47,16 @@
end

# installs gems
node[:rvm][:gems].each_pair do |ruby_gemset, gems|
node[:rvm][:gems].each_pair do |rstring, gems|
rvm_environment rstring

gems.each do |gem|
rvm_gem gem[:name] do
ruby ruby_gemset
version gem[:version] if gem[:version]
action gem[:action] if gem[:action]
options gem[:options] if gem[:options]
source gem[:source] if gem[:source]
ruby_string rstring
version gem[:version] if gem[:version]
action gem[:action] if gem[:action]
options gem[:options] if gem[:options]
source gem[:source] if gem[:source]
end
end
end
30 changes: 30 additions & 0 deletions resources/environment.rb
@@ -0,0 +1,30 @@
#
# Cookbook Name:: rvm
# Resource:: environment
#
# Author:: Fletcher Nichol <fnichol@nichol.ca>
#
# Copyright 2011, Fletcher Nichol
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

actions :create

attribute :ruby_string, :kind_of => String, :name_attribute => true

def initialize(name, run_context=nil)
super
@action = :create
@command = name
end
34 changes: 34 additions & 0 deletions resources/gem.rb
@@ -0,0 +1,34 @@
#
# Cookbook Name:: rvm
# Resource:: gem
#
# Author:: Fletcher Nichol <fnichol@nichol.ca>
#
# Copyright 2011, Fletcher Nichol
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

actions :install

attribute :gem, :kind_of => String, :name_attribute => true
attribute :ruby_string, :kind_of => String, :default => "default"
attribute :source, :kind_of => String
attribute :options, :kind_of => Hash
attribute :version, :kind_of => String

def initialize(name, run_context=nil)
super
@action = :install
@command = name
end

0 comments on commit 8ff1016

Please sign in to comment.