Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add new method 'ensure_rbenv_gem()' #13

Open
wants to merge 2 commits into from

2 participants

@veenstra

No description provided.

lib/terraform/dsl.rb
@@ -85,6 +85,21 @@ def ensure_gem(gem)
end
end
+ def rbenv_gem_installed?(gem, ruby_version = nil)
+ rbenv_root = ENV["RBENV_ROOT"] || "#{ENV["HOME"]}/.rbenv"
+ prefix = "env RBENV_VERSION=#{ruby_version} #{rbenv_root}/shims/" unless ruby_version.nil?
+ `#{prefix}gem list '#{gem}'`.include?(gem)
+ end
+
+ def ensure_rbenv_gem(gem, ruby_version = nil)
+ rbenv_root = ENV["RBENV_ROOT"] || "#{ENV["HOME"]}/.rbenv"
+ prefix = "env RBENV_VERSION=#{ruby_version} #{rbenv_root}/shims/" unless ruby_version.nil?
@philc Owner
philc added a note

Let's pull this prefix into its own method

Fixed in 81142da

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@philc
Owner

I've forgotten the context of this change. Can you describe the problem it's fixing?

@veenstra

It's been a while, but this allows the setup script do something like this:

ensure_rbenv_ruby("1.9.3-p194")
ensure_rbenv_gem("bundler", "1.9.3-p194")

This will install the bundler gem in the newly installed Ruby 1.9.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 5, 2013
  1. Add ability to ensure that a gem is installed using rbenv under a spe…

    Jack Veenstra authored
    …cific version of Ruby.
Commits on Mar 20, 2013
  1. Extract rbenv shim path construction into its own method.

    Jack Veenstra authored
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 0 deletions.
  1. +17 −0 lib/terraform/dsl.rb
View
17 lib/terraform/dsl.rb
@@ -85,6 +85,23 @@ def ensure_gem(gem)
end
end
+ def rbenv_shim_path(ruby_version)
+ return nil if ruby_version.nil?
+ rbenv_root = ENV["RBENV_ROOT"] || "#{ENV["HOME"]}/.rbenv"
+ "env RBENV_VERSION=#{ruby_version} #{rbenv_root}/shims/"
+ end
+
+ def rbenv_gem_installed?(gem, ruby_version = nil)
+ `#{rbenv_shim_path(ruby_version)}gem list '#{gem}'`.include?(gem)
+ end
+
+ def ensure_rbenv_gem(gem, ruby_version = nil)
+ dep "gem: #{gem}" do
+ met? { rbenv_gem_installed?(gem) }
+ meet { shell "#{rbenv_shim_path(ruby_version)}gem install #{gem} --no-ri --no-rdoc" }
+ end
+ end
+
# Ensures the file at dest_path is exactly the same as the one in source_path.
# Invokes the given block if the file is changed. Use this block to restart a service, for instance.
def ensure_file(source_path, dest_path, &on_change)
Something went wrong with that request. Please try again.