Rubygems front end?

E

Ezra Zygmuntowicz

Does one exist? I wanted to have a look at how one would go about
it. Or to be more specific, I need to make a web interface that I can
use to search the available gems, and list their descriptions and
versions. I can use the normal gem command line to actually install
stuff. But I want to do quick local auto complete searches of
available gems.

Basically all I need is the info that comes from a gem list --
remote. But I want to pull this info every few hours and insert it
into my database so I can use it in my web interface. What would be
the most polite way of doing this as far as rubygems are concerned?
Should I just parse the gem list --remote with regexes? Doesn't seem
like the way to go really. And http://docs.rubygems.org/ is down
right now so I can't read up on it.

Is there an easier way to do this built into rubygems already? I
suppose my next step will be to just read the source and figure it
out but if anyone has suggestions then please let me know,.


Cheers-
-Ezra
 
M

Matthew Harris

The Gem.source_index contains a source index object that contains lots
of information on available packages.
 
E

Ezra Zygmuntowicz

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,213
Messages
2,571,109
Members
47,701
Latest member
LeoraRober

Latest Threads

Top