New and Improved: better full text searching for ri/rdoc/gems
Published 2006-08-16 @ 16:47
Tagged ruby, rails, toys
During hacking night last night Eric and I added path independence and searching of gems and local installed ri/rdoc. Enjoy!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#!/usr/local/bin/ruby -w require 'rdoc/ri/ri_paths' require 'find' require 'yaml' search = ARGV.shift puts "Searching for #{search}" puts dirs = RI::Paths::PATH dirs.each do |dir| Dir.chdir dir do Find.find('.') do |path| next unless test ?f, path yaml = File.read path if yaml =~ /#{search}/io then full_name = $1 if yaml[/full_name: (.*)/] puts "** FOUND IN: #{full_name}" data = YAML.load yaml.gsub(/ \!.*/, '') desc = data['comment'].map { |x| x.values }.flatten.join("\n").gsub(/"/, "'").gsub(/</, "<").gsub(/>/, ">").gsub(/&/, "&") puts puts desc puts end end end end |