On Nov 11, 2007, at 3:01 PM, Justin H. wrote:
Thanks.
Posted via http://www.ruby-forum.com/.
Here is a script called gemcmd. This script is to be used in place of
the gem command. It will choose the proper platform and will install
the latest version of the requested gem available with no interaction
so it is suitable to be called from scripts.
Cheers-
-Ezra
#!/usr/bin/env ruby
#–
‘gemcmd’ - A non-interactive version of ‘gem’.
Original code
Copyright 2006 by Chad F., Rich Kilmer, Jim W. and others.
Monkey Patch by Todd F.:
Integrated into command line by Neil W. [email protected]
(c) 2007
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along
with this program; if not, write to the Free Software Foundation,
Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#++
require ‘rubygems’
Gem.manage_gems
required_version = Gem::Version::Requirement.new(“>= 1.8.0”)
unless required_version.satisfied_by?(Gem::Version.new(RUBY_VERSION))
puts “Expected Ruby Version #{required_version}, was #{RUBY_VERSION}”
exit(1)
end
Gem::RemoteInstaller.class_eval do
alias_method
:find_gem_to_install_without_ruby_only_platform, :find_gem_to_install
def find_gem_to_install( gem_name, version_requirement, caches =
nil )
if caches # old version of rubygems used to pass a caches object
caches.each {|k,v| caches[k].each { |name,spect|
caches[k].remove_spec(name) unless spec.platform ==
(ENV[‘GEMCMD_PLATFORM’]||Gem::Platform::RUBY) } }
find_gem_to_install_without_ruby_only_platform( gem_name,
version_requirement, caches )
else
Gem::StreamUI.class_eval do
alias_method
:choose_from_list_without_choosing_ruby_only, :choose_from_list
def choose_from_list( question, list )
result_index = -1
result= nil
list.each_with_index do |item,index|
if item.match(/(#{ENV[‘GEMCMD_PLATFORM’]||
Gem::Platform::RUBY})/)
result_index = index
result = item
break
end
end
return [result, result_index]
end
end
find_gem_to_install_without_ruby_only_platform( gem_name,
version_requirement )
end
end
end
We need to preserve the original ARGV to use for passing gem options
to source gems. If there is a – in the line, strip all options after
it…its for the source building process.
args = !ARGV.include?(“–”) ? ARGV.clone : ARGV[0…ARGV.index(“–”)]
Gem::GemRunner.new.run(args)