lib/jim/index.rb in jim-0.1.1 vs lib/jim/index.rb in jim-0.1.2
- old
+ new
@@ -12,22 +12,19 @@
end
def list
list = {}
each_file_in_index('.js') do |filename|
- if version = filename.version
- name = filename.stem.gsub(/(\-[^\-]+)$/, '')
- elsif /lib\/([^\/]+)-([\d\w\.\-]+)\/.+/.match filename
+ if /lib\/([^\/]+)-([\d\w\.\-]+)\/.+/.match filename
name = $1
version = $2
else
- name = filename.stem
- version = '0'
+ name, version = Jim::VersionParser.parse_filename(filename)
end
if name && version
list[name] ||= []
- list[name] << version unless list[name].include?(version)
+ list[name] << [version, filename]
end
end
list.sort
end
@@ -49,15 +46,21 @@
final = false
each_file_in_index(ext) do |filename|
possible_paths.each do |p|
if File.file?(filename) && p.match(filename)
final = Pathname.new(filename).expand_path
- break
+ block_given? ? yield(final) : break
end
end
- break if final
+ break if final && !block_given?
end
final
+ end
+
+ def find_all(name, version = nil)
+ matched = []
+ find(name, version) {|p| matched << p }
+ matched
end
def each_file_in_index(ext, &block)
@directories.each do |dir|
Dir.glob(Pathname.new(dir) + '**' + "*#{ext}") do |filename|
\ No newline at end of file