Package, noun => class.
This commit is contained in:
parent
a809fcbdd5
commit
5ea99e2c24
39
qwandry.rb
39
qwandry.rb
@ -23,6 +23,10 @@ module Qwandry
|
||||
def scan(name)
|
||||
[]
|
||||
end
|
||||
|
||||
def package(name, paths)
|
||||
Package.new(name, paths, self)
|
||||
end
|
||||
end
|
||||
|
||||
# Directories look like:
|
||||
@ -31,10 +35,29 @@ module Qwandry
|
||||
# lib-0.2
|
||||
class FlatRepository < Repository
|
||||
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
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
if __FILE__ == $0
|
||||
@ -56,20 +79,20 @@ if __FILE__ == $0
|
||||
load('repositories.rb')
|
||||
|
||||
name = ARGV.pop
|
||||
candidates = []
|
||||
packages = []
|
||||
|
||||
@repositories.each do |set, repos|
|
||||
repos.each do |repo|
|
||||
candidates.concat(repo.scan(name))
|
||||
packages.concat(repo.scan(name))
|
||||
end
|
||||
end
|
||||
|
||||
candidates.each_with_index do |path, index|
|
||||
puts " #{index+1}. #{File.basename path}"
|
||||
packages.each_with_index do |package, index|
|
||||
puts " #{index+1}. #{package.name}"
|
||||
end
|
||||
|
||||
print ">> "
|
||||
index = gets.to_i-1
|
||||
path = candidates[index]
|
||||
`mate #{path}`
|
||||
package = packages[index]
|
||||
`mate #{package.paths.join(' ')}` if package
|
||||
end
|
@ -4,8 +4,8 @@ def which(bin)
|
||||
`which #{bin}`.chomp
|
||||
end
|
||||
|
||||
def add(label, path)
|
||||
@repositories[label.to_s] << Qwandry::FlatRepository.new(path)
|
||||
def add(label, path, repository_type=Qwandry::FlatRepository)
|
||||
@repositories[label.to_s] << repository_type.new(path)
|
||||
end
|
||||
|
||||
if which('ruby') == '/Users/adam/.rvm/rubies/ruby-1.9.1-p378/bin/ruby'
|
||||
|
Loading…
Reference in New Issue
Block a user