lib/bpm/project.rb in bpm-0.1.2 vs lib/bpm/project.rb in bpm-0.1.3

- old
+ new

@@ -201,30 +201,43 @@ # Returns the package object and module id for the path. Path must match # a package known to the project. def package_and_module_from_path(path) path = File.expand_path path.to_s - pkg = local_deps.find {|cur| path =~ /^#{Regexp.escape cur.root_path.to_s}/} + pkg = local_deps.find {|cur| path =~ /^#{Regexp.escape cur.root_path.to_s}\//} pkg = self if pkg.nil? && path =~ /^#{Regexp.escape root_path.to_s}/ raise "#{path} is not within a known package" if pkg.nil? - - path = Pathname.new(path).relative_path_from(Pathname.new(pkg.root_path)).split.map { |x| x.to_s } - - dir_name = pkg.directories.find do |dir_key, dname| - Array(dname).include?(path.first) + + dir_name = nil + pkg.directories.each do |dname, dpath| + dpaths = Array(dpath).map{|d| File.expand_path(d, pkg.root_path) } + dpaths.each do |d| + # Find a match and see if we can replace + if path.gsub!(/^#{Regexp.escape(d)}\//, "#{dname}/") + dir_name = dname + break + end + end + break if dir_name end - - dir_name = dir_name ? dir_name.first : path.first + + if dir_name + parts = path.split("/") + else + parts = Pathname.new(path).relative_path_from(Pathname.new(pkg.root_path)).to_s.split("/") + dir_name = parts.first + end + if dir_name == 'lib' - path.shift + parts.shift else - path[0] = "~#{dir_name}" + parts[0] = "~#{dir_name}" end - - path[path.size-1] = File.basename path.last, '.*' - [pkg, path.join('/')] + + parts[parts.size-1] = File.basename(parts.last, '.*') + [pkg, parts.join('/')] end - + def local_deps(verbose=false) @local_deps ||= build_local_deps end