refining repositories a little, there are a few common layouts. We will start with flat ones.

This commit is contained in:
Adam Sanderson 2010-08-05 08:09:58 -07:00
parent 8062659921
commit e6a23d045b
2 changed files with 25 additions and 11 deletions

View File

@ -17,6 +17,24 @@ if ARGV.length != 1
exit(-1)
end
##
class Repository
def initialize(path)
@path = path.chomp('/')
end
def scan(name)
[]
end
end
class FlatRepository < Repository
def scan(name)
Dir["#{@path}/*"].select{|path| path if File.basename(path).start_with?(name)}
end
end
##
load('repositories.rb')
name = ARGV.pop
@ -24,7 +42,7 @@ candidates = []
@repositories.each do |set, repos|
repos.each do |repo|
Dir["#{repo}/*"].each{|path| candidates << path if File.basename(path).start_with?(name)}
candidates.concat(repo.scan(name))
end
end
@ -33,6 +51,6 @@ candidates.each_with_index do |path, index|
end
print ">> "
index = gets
path = candidates[index.to_i-1]
index = gets.to_i-1
path = candidates[index]
`mate #{path}`

View File

@ -4,15 +4,11 @@ def which(bin)
`which #{bin}`.chomp
end
def add(repository, path=nil)
if !path
path = repository
repository = 'default'
end
@repositories[repository] << path
def add(label, path)
@repositories[label.to_s] << FlatRepository.new(path)
end
if which('ruby') == '/Users/adam/.rvm/rubies/ruby-1.9.1-p378/bin/ruby'
add 'gem', '/Users/adam/.rvm/gems/ruby-1.9.1-p378/gems/'
add :gem, '/Users/adam/.rvm/gems/ruby-1.9.1-p378/gems/'
add :ruby, '/Users/adam/.rvm/rubies/ruby-1.9.1-p378/lib/ruby/1.9.1/'
end