lib/jim/index.rb in jim-0.2.0 vs lib/jim/index.rb in jim-0.2.1

- old
+ new

@@ -2,18 +2,19 @@ # Index managages a list of directories which are searched to find requirements class Index attr_reader :directories def initialize(*directories) - @directories = directories.flatten.compact + @directories = [directories].flatten.compact + @jimhome_re = /#{Pathname.new(@directories.first).expand_path.to_s}/ end def add(directory) @directories.unshift directory end - def list + def list(search = nil) list = {} each_file_in_index('.js') do |filename| if /lib\/([^\/\-]+)-([\d\w\.\-]+)\/.+/.match filename name = $1 version = $2 @@ -23,10 +24,14 @@ if name && version list[name] ||= [] list[name] << [version, filename] end end + if search + search = /#{search}/i + list = list.find_all {|lib| lib[0] =~ search } + end list.sort end def find(name, version = nil) name = Pathname.new(name) @@ -52,9 +57,13 @@ end end break if final && !block_given? end final + end + + def in_jimhome?(path) + !!(path.to_s =~ @jimhome_re) end def find_all(name, version = nil) matched = [] find(name, version) {|p| matched << p } \ No newline at end of file