Recognize ruby standard library idioms.

This commit is contained in:
Adam Sanderson 2010-11-08 21:02:43 -08:00
parent 127a76f5ba
commit ac5e9c233a
6 changed files with 34 additions and 11 deletions

2
TODO Normal file
View File

@ -0,0 +1,2 @@
- Differentiate multiple similar matches (show path or repository label)
- Recognize file idioms such as './file.rb' and matching "./file/" @done

View File

@ -17,6 +17,6 @@ module Qwandry
autoload :Launcher, "qwandry/launcher"
autoload :Repository, "qwandry/repository"
autoload :FlatRepository, "qwandry/flat_repository"
autoload :LibraryRepository, "qwandry/library_repository"
autoload :Package, "qwandry/package"
end

View File

@ -1,8 +1,7 @@
module Qwandry
# Directories look like:
# Repository
# lib-0.1
# lib-0.2
# ./lib-0.1
# ./lib-0.2
class FlatRepository < Qwandry::Repository
def scan(name)
results = []

View File

@ -45,7 +45,7 @@ module Qwandry
# tend to contain only binaries
def add_ruby_repositories
($:).grep(/lib\/ruby/).reject{|path| path =~ /#{RUBY_PLATFORM}$/}.each do |path|
add :ruby, path
add :ruby, path, Qwandry::LibraryRepository
end
end

View File

@ -0,0 +1,22 @@
module Qwandry
# Directories look like:
# lib1.rb
# ./lib1
# lib2.py
# ./lib2
class LibraryRepository < Qwandry::Repository
def scan(name)
results = Hash.new{|h,k| h[k] = package(k)}
Dir["#{@path}/*"].select do |path|
basename = File.basename(path)
if basename.start_with?(name)
# strip any file extension
basename.sub! /\.\w+$/,'' unless File.directory?(path)
results[basename].paths << path
end
end
results.values.sort_by{|package| package.name}
end
end
end

View File

@ -11,7 +11,7 @@ module Qwandry
[]
end
def package(name, paths)
def package(name, paths=[])
Package.new(name, paths, self)
end
end