Permalink
Browse files

Added support for creating and removing gemsets

  • Loading branch information...
1 parent 419ba5f commit 20f9f9146720068267adada7a4352aa3c068e76f Brandon Turner committed Aug 19, 2011
Showing with 86 additions and 1 deletion.
  1. +12 −1 README.markdown
  2. +50 −0 lib/puppet/provider/rvm_gemset/gemset.rb
  3. +24 −0 lib/puppet/type/rvm_gemset.rb
View
@@ -115,7 +115,18 @@ Alternatively, you can use this less verbose, but slightly uglier syntax:
}
}
-Gems will be installed to the default RVM gemset. This module doesn't support configuring gemsets.
+
+## Creating Gemsets
+
+Create a gemset with:
+
+ if $rvm_installed == "true" {
+ rvm_gemset {
+ "ruby-1.9.2-p290/myproject":
+ ensure => present,
+ require => Rvm_system_ruby['ruby-1.9.2-p290'];
+ }
+ }
## Installing Passenger
@@ -0,0 +1,50 @@
+# RVM gemset support
+Puppet::Type.type(:rvm_gemset).provide(:gemset) do
+ desc "RVM gemset support."
+
+ commands :rvmcmd => "/usr/local/rvm/bin/rvm"
+
+ def ruby_version
+ resource[:ruby_version]
+ end
+
+ def gemset_name
+ resource[:name]
+ end
+
+ def gemsetcommand
+ [command(:rvmcmd), ruby_version, "exec", "rvm", "gemset"]
+ end
+
+ def gemsetcommand_force
+ [command(:rvmcmd), ruby_version, "exec", "rvm", "--force", "gemset"]
+ end
+
+ def gemset_list
+ list = []
+
+ command = gemsetcommand + ['list']
+ output = execute(command)
+ output.lines do |line|
+ if line =~ /^\s+\S+/
+ list << line.strip
+ end
+ end
+
+ list
+ end
+
+ def create
+ command = gemsetcommand + ['create', gemset_name]
+ execute(command)
+ end
+
+ def destroy
+ command = gemsetcommand_force + ['delete', gemset_name]
+ execute(command)
+ end
+
+ def exists?
+ gemset_list.include? gemset_name
+ end
+end
@@ -0,0 +1,24 @@
+Puppet::Type.newtype(:rvm_gemset) do
+ @doc = "Manage RVM Gemsets."
+
+ def self.title_patterns
+ [ [ /^(?:(.*)\/)?(.*)$/, [ [ :ruby_version, lambda{|x| x} ], [ :name, lambda{|x| x} ] ] ] ]
+ end
+
+ ensurable
+
+ newparam(:name) do
+ desc "The name of the gemset to be managed."
+ isnamevar
+ end
+
+ newparam(:ruby_version) do
+ desc "The ruby version to use. This should be the fully qualified RVM string.
+ For example: 'ruby-1.9.2-p290'
+ For a full list of known strings: `rvm list known_strings`."
+
+ defaultto "ruby-1.9.2-p290"
+ isnamevar
+ end
+
+end

0 comments on commit 20f9f91

Please sign in to comment.