Ezra Zygmuntowicz
9/29/2006 3:31:00 PM
Thanks for the responses. I ended up just regexing the gem list --
remote output as it was simple to do. I'll share here in case someone
else ends up wanting something like this. Here is a rake task that
will pull the gem list and parse it into a hash with he name of the
gem as the key and versions and descriptions as subhashes of the gem
name key. THen it populates a bunch of GemIndex ActiveRecord Objects.
namespace :parsegems do
def parse_gems(gem_list)
hsh={}
last = ''
gem_list.each do |line|
case line
when /(\w+)\s+\((.*?)\)/
(hsh[$1] ||= {})[:versions]=$2
last = $1
when /\A(\s+\w.*?)\Z/
(hsh[last][:desc] ||= '') << ($1+' ')
end
end
hsh
end
desc 'Gets the gems list --remote and parse it into the app_gems
database table for quick autocomplete.'
task :import => :environment do
hsh = parse_gems(`gem list --remote`)
hsh.keys.each do |key|
g = GemIndex.find_or_create_by_name(key)
g.update_attributes :versions => hsh[key][:versions],
:description => hsh[key][:desc]
puts "Imported Gem Data for: #{key}"
end
end
end
Cheers-
-Ezra