Package, noun => class.

This commit is contained in:
Adam Sanderson 2010-08-06 09:48:52 -07:00
parent a809fcbdd5
commit 5ea99e2c24
2 changed files with 33 additions and 10 deletions

View File

@ -23,6 +23,10 @@ module Qwandry
def scan(name) def scan(name)
[] []
end end
def package(name, paths)
Package.new(name, paths, self)
end
end end
# Directories look like: # Directories look like:
@ -31,10 +35,29 @@ module Qwandry
# lib-0.2 # lib-0.2
class FlatRepository < Repository class FlatRepository < Repository
def scan(name) def scan(name)
Dir["#{@path}/*"].select{|path| path if File.basename(path).start_with?(name)} results = []
Dir["#{@path}/*"].select do |path|
if File.basename(path).start_with?(name)
results << package(File.basename(path), [path])
end
end
results
end end
end end
class Package
attr_reader :name
attr_reader :repository
attr_reader :paths
def initialize(name, paths, repository)
@name = name
@repository = repository
@paths = paths
end
end
end end
if __FILE__ == $0 if __FILE__ == $0
@ -56,20 +79,20 @@ if __FILE__ == $0
load('repositories.rb') load('repositories.rb')
name = ARGV.pop name = ARGV.pop
candidates = [] packages = []
@repositories.each do |set, repos| @repositories.each do |set, repos|
repos.each do |repo| repos.each do |repo|
candidates.concat(repo.scan(name)) packages.concat(repo.scan(name))
end end
end end
candidates.each_with_index do |path, index| packages.each_with_index do |package, index|
puts " #{index+1}. #{File.basename path}" puts " #{index+1}. #{package.name}"
end end
print ">> " print ">> "
index = gets.to_i-1 index = gets.to_i-1
path = candidates[index] package = packages[index]
`mate #{path}` `mate #{package.paths.join(' ')}` if package
end end

View File

@ -4,8 +4,8 @@ def which(bin)
`which #{bin}`.chomp `which #{bin}`.chomp
end end
def add(label, path) def add(label, path, repository_type=Qwandry::FlatRepository)
@repositories[label.to_s] << Qwandry::FlatRepository.new(path) @repositories[label.to_s] << repository_type.new(path)
end end
if which('ruby') == '/Users/adam/.rvm/rubies/ruby-1.9.1-p378/bin/ruby' if which('ruby') == '/Users/adam/.rvm/rubies/ruby-1.9.1-p378/bin/ruby'