lib/rake/funnel/extensions/common_path.rb in rake-funnel-0.18.0 vs lib/rake/funnel/extensions/common_path.rb in rake-funnel-0.19.0

- old
+ new

@@ -5,30 +5,31 @@ module Funnel module Extensions module CommonPath def common_path list = to_a - .compact - .map { |x| components(x) } + .compact + .map { |x| components(x) } min = list.min_by(&:length) matches = find_matches(list, min) matches.min_by(&:length) || '' end private + def components(path) paths = [] Pathname.new(path).descend do |p| paths << p end - paths = paths.inject([]) { |components, p| + paths = paths.inject([]) do |components, p| relative = p.relative_path_from(components.last[:absolute]) if components.any? components << { absolute: p, relative: relative || p } - } + end paths.map { |component| component[:relative].to_s } end def find_matches(list, min)