Recognize ruby standard library idioms.
This commit is contained in:
parent
127a76f5ba
commit
ac5e9c233a
|
@ -0,0 +1,2 @@
|
||||||
|
- Differentiate multiple similar matches (show path or repository label)
|
||||||
|
- Recognize file idioms such as './file.rb' and matching "./file/" @done
|
|
@ -17,6 +17,6 @@ module Qwandry
|
||||||
autoload :Launcher, "qwandry/launcher"
|
autoload :Launcher, "qwandry/launcher"
|
||||||
autoload :Repository, "qwandry/repository"
|
autoload :Repository, "qwandry/repository"
|
||||||
autoload :FlatRepository, "qwandry/flat_repository"
|
autoload :FlatRepository, "qwandry/flat_repository"
|
||||||
|
autoload :LibraryRepository, "qwandry/library_repository"
|
||||||
autoload :Package, "qwandry/package"
|
autoload :Package, "qwandry/package"
|
||||||
|
|
||||||
end
|
end
|
|
@ -1,8 +1,7 @@
|
||||||
module Qwandry
|
module Qwandry
|
||||||
# Directories look like:
|
# Directories look like:
|
||||||
# Repository
|
# ./lib-0.1
|
||||||
# lib-0.1
|
# ./lib-0.2
|
||||||
# lib-0.2
|
|
||||||
class FlatRepository < Qwandry::Repository
|
class FlatRepository < Qwandry::Repository
|
||||||
def scan(name)
|
def scan(name)
|
||||||
results = []
|
results = []
|
||||||
|
|
|
@ -45,7 +45,7 @@ module Qwandry
|
||||||
# tend to contain only binaries
|
# tend to contain only binaries
|
||||||
def add_ruby_repositories
|
def add_ruby_repositories
|
||||||
($:).grep(/lib\/ruby/).reject{|path| path =~ /#{RUBY_PLATFORM}$/}.each do |path|
|
($:).grep(/lib\/ruby/).reject{|path| path =~ /#{RUBY_PLATFORM}$/}.each do |path|
|
||||||
add :ruby, path
|
add :ruby, path, Qwandry::LibraryRepository
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
@ -11,7 +11,7 @@ module Qwandry
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
def package(name, paths)
|
def package(name, paths=[])
|
||||||
Package.new(name, paths, self)
|
Package.new(name, paths, self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue