From e6a23d045b17fc0dc9e5721018afc577d6676139 Mon Sep 17 00:00:00 2001 From: Adam Sanderson Date: Thu, 5 Aug 2010 08:09:58 -0700 Subject: [PATCH] refining repositories a little, there are a few common layouts. We will start with flat ones. --- qwandry.rb | 24 +++++++++++++++++++++--- repositories.rb | 12 ++++-------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/qwandry.rb b/qwandry.rb index 8fe48d5..4c7a1c8 100755 --- a/qwandry.rb +++ b/qwandry.rb @@ -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}` \ No newline at end of file diff --git a/repositories.rb b/repositories.rb index 4d75290..06e6afa 100644 --- a/repositories.rb +++ b/repositories.rb @@ -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 \ No newline at end of file