tags:

views:

136

answers:

1

is there some ruby code I can use to install a gem from a local file, if that gem is not installed?

i'm thinking it would look something like:

if !gem_installed("some gem name")
  system "gem install -l local_copy.gem"
end

i don't know if anything exists that lets me check for gems like this or not...

+3  A: 

Checking availability is covered in this previous StackOverflow Quesiton

begin
  gem "somegem"
  # with requirements
  gem "somegem", ">=2.0"
rescue GEM::LoadError
  # not installed
end

or

matches = Gem.source_index.find_name(gem.name, gem.version_requirements)

As for the install, it looks like rails uses the system for gem install also

 puts %x(#{cmd})
jrhicks